# HG changeset patch # User Sebastien Jodogne # Date 1546452255 -3600 # Node ID 8bc2cb1335f47eacf905b0c948c1e17ad9c9eeb1 # Parent ead8576a02efa8310588b8304e359576fa88b7fd OrthancPluginDatabase::ApplyLookupResources() using fast lookup diff -r ead8576a02ef -r 8bc2cb1335f4 Plugins/Engine/OrthancPluginDatabase.cpp --- a/Plugins/Engine/OrthancPluginDatabase.cpp Wed Jan 02 18:39:25 2019 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Wed Jan 02 19:04:15 2019 +0100 @@ -133,6 +133,8 @@ answerChanges_ = NULL; answerExportedResources_ = NULL; answerDone_ = NULL; + answerMatchingResources_ = NULL; + answerMatchingInstances_ = NULL; } @@ -224,15 +226,12 @@ void *payload) : library_(library), errorDictionary_(errorDictionary), - type_(_OrthancPluginDatabaseAnswerType_None), backend_(backend), payload_(payload), - listener_(NULL), - answerDicomMap_(NULL), - answerChanges_(NULL), - answerExportedResources_(NULL), - answerDone_(NULL) + listener_(NULL) { + ResetAnswers(); + memset(&extensions_, 0, sizeof(extensions_)); size_t size = sizeof(extensions_); @@ -242,6 +241,11 @@ } memcpy(&extensions_, extensions, size); + + if (extensions_.lookupResources == NULL) + { + LOG(WARNING) << "Performance warning in index plugin: Fast lookup is not available"; + } } @@ -960,6 +964,17 @@ answerExportedResources_->clear(); break; + case _OrthancPluginDatabaseAnswerType_MatchingResource: + assert(answerMatchingResources_ != NULL); + answerMatchingResources_->clear(); + + if (answerMatchingInstances_ != NULL) + { + answerMatchingInstances_->clear(); + } + + break; + default: throw OrthancException(ErrorCode_DatabasePlugin, "Unhandled type of answer for custom index plugin: " + @@ -1088,6 +1103,32 @@ break; } + case _OrthancPluginDatabaseAnswerType_MatchingResource: + { + const OrthancPluginMatchingResource& match = + *reinterpret_cast(answer.valueGeneric); + + if (match.resourceId == NULL) + { + throw OrthancException(ErrorCode_DatabasePlugin); + } + + assert(answerMatchingResources_ != NULL); + answerMatchingResources_->push_back(match.resourceId); + + if (answerMatchingInstances_ != NULL) + { + if (match.someInstanceId == NULL) + { + throw OrthancException(ErrorCode_DatabasePlugin); + } + + answerMatchingInstances_->push_back(match.someInstanceId); + } + + break; + } + default: throw OrthancException(ErrorCode_DatabasePlugin, "Unhandled type of answer for custom index plugin: " + @@ -1118,12 +1159,32 @@ { if (extensions_.lookupResources == NULL) { + // Fallback to compatibility mode CompatibilityDatabaseWrapper::ApplyLookupResources (resourcesId, instancesId, lookup, queryLevel, limit); } else { + std::vector constraints; + std::vector< std::vector > constraintsValues; + + constraints.resize(lookup.size()); + constraintsValues.resize(lookup.size()); + + for (size_t i = 0; i < lookup.size(); i++) + { + lookup[i].EncodeForPlugins(constraints[i], constraintsValues[i]); + } + + answerMatchingResources_ = &resourcesId; + answerMatchingInstances_ = instancesId; + ResetAnswers(); + + CheckSuccess(extensions_.lookupResources(GetContext(), payload_, lookup.size(), + (lookup.empty() ? NULL : &constraints[0]), + Plugins::Convert(queryLevel), + limit, (instancesId == NULL ? 0 : 1))); } } diff -r ead8576a02ef -r 8bc2cb1335f4 Plugins/Engine/OrthancPluginDatabase.h --- a/Plugins/Engine/OrthancPluginDatabase.h Wed Jan 02 18:39:25 2019 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.h Wed Jan 02 19:04:15 2019 +0100 @@ -70,6 +70,8 @@ std::list* answerChanges_; std::list* answerExportedResources_; bool* answerDone_; + std::list* answerMatchingResources_; + std::list* answerMatchingInstances_; OrthancPluginDatabaseContext* GetContext() { diff -r ead8576a02ef -r 8bc2cb1335f4 Plugins/Include/orthanc/OrthancCDatabasePlugin.h --- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Wed Jan 02 18:39:25 2019 +0100 +++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Wed Jan 02 19:04:15 2019 +0100 @@ -740,7 +740,7 @@ /* inputs */ void* payload, uint32_t constraintsCount, - const OrthancPluginDatabaseConstraint* const* constraints, + const OrthancPluginDatabaseConstraint* constraints, OrthancPluginResourceType queryLevel, uint32_t limit, uint8_t requestSomeInstance);