# HG changeset patch # User Sebastien Jodogne # Date 1546450765 -3600 # Node ID ead8576a02efa8310588b8304e359576fa88b7fd # Parent 495c5edce708e109c5569bd9e7e9b0734b13a697 IDatabaseWrapper::ApplyLookupResources now returns lists diff -r 495c5edce708 -r ead8576a02ef OrthancServer/IDatabaseWrapper.h --- a/OrthancServer/IDatabaseWrapper.h Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/IDatabaseWrapper.h Wed Jan 02 18:39:25 2019 +0100 @@ -212,8 +212,8 @@ virtual bool IsDiskSizeAbove(uint64_t threshold) = 0; - virtual void ApplyLookupResources(std::vector& resourcesId, - std::vector* instancesId, // Can be NULL if not needed + virtual void ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, // Can be NULL if not needed const std::vector& lookup, ResourceType queryLevel, size_t limit) = 0; diff -r 495c5edce708 -r ead8576a02ef OrthancServer/SQLiteDatabaseWrapper.cpp --- a/OrthancServer/SQLiteDatabaseWrapper.cpp Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/SQLiteDatabaseWrapper.cpp Wed Jan 02 18:39:25 2019 +0100 @@ -1145,8 +1145,8 @@ }; - static void AnswerLookup(std::vector& resourcesId, - std::vector& instancesId, + static void AnswerLookup(std::list& resourcesId, + std::list& instancesId, SQLite::Connection& db, ResourceType level) { @@ -1219,8 +1219,8 @@ } - void SQLiteDatabaseWrapper::ApplyLookupResources(std::vector& resourcesId, - std::vector* instancesId, + void SQLiteDatabaseWrapper::ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, const std::vector& lookup, ResourceType queryLevel, size_t limit) diff -r 495c5edce708 -r ead8576a02ef OrthancServer/SQLiteDatabaseWrapper.h --- a/OrthancServer/SQLiteDatabaseWrapper.h Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/SQLiteDatabaseWrapper.h Wed Jan 02 18:39:25 2019 +0100 @@ -314,8 +314,8 @@ virtual bool IsDiskSizeAbove(uint64_t threshold) ORTHANC_OVERRIDE; - virtual void ApplyLookupResources(std::vector& resourcesId, - std::vector* instancesId, + virtual void ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, const std::vector& lookup, ResourceType queryLevel, size_t limit) diff -r 495c5edce708 -r ead8576a02ef OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.cpp --- a/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.cpp Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.cpp Wed Jan 02 18:39:25 2019 +0100 @@ -40,8 +40,8 @@ { namespace Compatibility { - void CompatibilityDatabaseWrapper::ApplyLookupResources(std::vector& resourcesId, - std::vector* instancesId, + void CompatibilityDatabaseWrapper::ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, const std::vector& lookup, ResourceType queryLevel, size_t limit) diff -r 495c5edce708 -r ead8576a02ef OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h --- a/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h Wed Jan 02 18:39:25 2019 +0100 @@ -55,8 +55,8 @@ class CompatibilityDatabaseWrapper : public IDatabaseWrapper { public: - virtual void ApplyLookupResources(std::vector& resourcesId, - std::vector* instancesId, + virtual void ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, const std::vector& lookup, ResourceType queryLevel, size_t limit) diff -r 495c5edce708 -r ead8576a02ef OrthancServer/Search/Compatibility/DatabaseLookup.cpp --- a/OrthancServer/Search/Compatibility/DatabaseLookup.cpp Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/Search/Compatibility/DatabaseLookup.cpp Wed Jan 02 18:39:25 2019 +0100 @@ -312,8 +312,8 @@ } - void DatabaseLookup::ApplyLookupResources(std::vector& resourcesId, - std::vector* instancesId, + void DatabaseLookup::ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, const std::vector& lookup, ResourceType queryLevel, size_t limit) @@ -389,13 +389,6 @@ // Get the public ID of all the selected resources - resourcesId.resize(resources.size()); - - if (instancesId != NULL) - { - instancesId->resize(resources.size()); - } - size_t pos = 0; for (std::list::const_iterator @@ -403,18 +396,20 @@ { assert(database_.GetResourceType(*it) == queryLevel); - resourcesId[pos] = database_.GetPublicId(*it); + const std::string resource = database_.GetPublicId(*it); + resourcesId.push_back(resource); if (instancesId != NULL) { - // Collect one child instance for each of the selected resources if (queryLevel == ResourceType_Instance) { - (*instancesId) [pos] = resourcesId[pos]; + // The resource is itself the instance + instancesId->push_back(resource); } else { - (*instancesId) [pos] = GetOneInstance(database_, *it, queryLevel); + // Collect one child instance for each of the selected resources + instancesId->push_back(GetOneInstance(database_, *it, queryLevel)); } } } diff -r 495c5edce708 -r ead8576a02ef OrthancServer/Search/Compatibility/DatabaseLookup.h --- a/OrthancServer/Search/Compatibility/DatabaseLookup.h Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/Search/Compatibility/DatabaseLookup.h Wed Jan 02 18:39:25 2019 +0100 @@ -50,8 +50,8 @@ { } - void ApplyLookupResources(std::vector& resourcesId, - std::vector* instancesId, + void ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, const std::vector& lookup, ResourceType queryLevel, size_t limit); diff -r 495c5edce708 -r ead8576a02ef OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Wed Jan 02 15:50:44 2019 +0100 +++ b/OrthancServer/ServerIndex.cpp Wed Jan 02 18:39:25 2019 +0100 @@ -58,6 +58,22 @@ namespace Orthanc { + static void CopyListToVector(std::vector& target, + const std::list& source) + { + target.resize(source.size()); + + size_t pos = 0; + + for (std::list::const_iterator + it = source.begin(); it != source.end(); ++it) + { + target[pos] = *it; + pos ++; + } + } + + class ServerIndex::Listener : public IDatabaseListener { private: @@ -2141,10 +2157,14 @@ std::vector query; query.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier)); + std::list tmp; + { boost::mutex::scoped_lock lock(mutex_); - db_.ApplyLookupResources(result, NULL, query, level, 0); + db_.ApplyLookupResources(tmp, NULL, query, level, 0); } + + CopyListToVector(result, tmp); } @@ -2570,9 +2590,26 @@ std::vector normalized; NormalizeLookup(normalized, lookup, queryLevel); + std::list resourcesList, instancesList; + { boost::mutex::scoped_lock lock(mutex_); - db_.ApplyLookupResources(resourcesId, instancesId, normalized, queryLevel, limit); + + if (instancesId == NULL) + { + db_.ApplyLookupResources(resourcesList, NULL, normalized, queryLevel, limit); + } + else + { + db_.ApplyLookupResources(resourcesList, &instancesList, normalized, queryLevel, limit); + } + } + + CopyListToVector(resourcesId, resourcesList); + + if (instancesId != NULL) + { + CopyListToVector(*instancesId, instancesList); } } } diff -r 495c5edce708 -r ead8576a02ef Plugins/Engine/OrthancPluginDatabase.cpp --- a/Plugins/Engine/OrthancPluginDatabase.cpp Wed Jan 02 15:50:44 2019 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Wed Jan 02 18:39:25 2019 +0100 @@ -1110,6 +1110,24 @@ } + void OrthancPluginDatabase::ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, + const std::vector& lookup, + ResourceType queryLevel, + size_t limit) + { + if (extensions_.lookupResources == NULL) + { + CompatibilityDatabaseWrapper::ApplyLookupResources + (resourcesId, instancesId, lookup, queryLevel, limit); + } + else + { + ResetAnswers(); + } + } + + void OrthancPluginDatabase::LookupIdentifier(std::list& result, ResourceType level, const DicomTag& tag, diff -r 495c5edce708 -r ead8576a02ef Plugins/Engine/OrthancPluginDatabase.h --- a/Plugins/Engine/OrthancPluginDatabase.h Wed Jan 02 15:50:44 2019 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.h Wed Jan 02 18:39:25 2019 +0100 @@ -307,6 +307,13 @@ virtual bool IsDiskSizeAbove(uint64_t threshold) ORTHANC_OVERRIDE; + virtual void ApplyLookupResources(std::list& resourcesId, + std::list* instancesId, + const std::vector& lookup, + ResourceType queryLevel, + size_t limit) + ORTHANC_OVERRIDE; + // From the "CompatibilityDatabaseWrapper" interface virtual void GetAllInternalIds(std::list& target, ResourceType resourceType) diff -r 495c5edce708 -r ead8576a02ef UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Wed Jan 02 15:50:44 2019 +0100 +++ b/UnitTestsSources/ServerIndexTests.cpp Wed Jan 02 18:39:25 2019 +0100 @@ -249,7 +249,7 @@ } - void DoLookupIdentifier(std::vector& result, + void DoLookupIdentifier(std::list& result, ResourceType level, const DicomTag& tag, ConstraintType type, @@ -266,7 +266,7 @@ } - void DoLookupIdentifier2(std::vector& result, + void DoLookupIdentifier2(std::list& result, ResourceType level, const DicomTag& tag, ConstraintType type1, @@ -740,7 +740,7 @@ index_->SetIdentifierTag(a[2], DICOM_TAG_STUDY_INSTANCE_UID, "0"); index_->SetIdentifierTag(a[3], DICOM_TAG_SERIES_INSTANCE_UID, "0"); - std::vector s; + std::list s; DoLookupIdentifier(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, ConstraintType_Equal, "0"); ASSERT_EQ(2u, s.size());