changeset 673:d3af76826278 find-refactoring

optimization thanks to ExtendedFind
author Alain Mazy <am@orthanc.team>
date Mon, 16 Sep 2024 11:20:07 +0200 (9 months ago)
parents c302094b719e
children 882743589c73
files NEWS Plugin/Plugin.cpp Plugin/WadoRs.cpp Plugin/WadoRs.h
diffstat 4 files changed, 39 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Sep 04 12:56:30 2024 +0200
+++ b/NEWS	Mon Sep 16 11:20:07 2024 +0200
@@ -5,6 +5,7 @@
 * Fixed parsing of numerical values in QIDO-RS response that prevented, amongst other,
   the retrieval of NumberOfStudyRelatedInstances, NumberOfStudyRelatedSeries, ...
 * Fixed non latin PatientName values that were empty in some QIDO-RS responses.
+* Optimization when running with an Orthanc that supports the ExtendedFind.
 
 
 Version 1.17 (2024-06-05)
--- a/Plugin/Plugin.cpp	Wed Sep 04 12:56:30 2024 +0200
+++ b/Plugin/Plugin.cpp	Mon Sep 16 11:20:07 2024 +0200
@@ -42,7 +42,8 @@
 #define ORTHANC_CORE_MINIMAL_REVISION  0
 
 static const char* const HAS_DELETE = "HasDelete";
-
+static const char* const SYSTEM_CAPABILITIES = "Capabilities";
+static const char* const SYSTEM_CAPABILITIES_HAS_EXTENDED_FIND = "HasExtendedFind";
 
 
 bool RequestHasKey(const OrthancPluginHttpRequest* request, const char* key)
@@ -471,8 +472,27 @@
     switch (changeType)
     {
       case OrthancPluginChangeType_OrthancStarted:
+      {
         OrthancPlugins::Configuration::LoadDicomWebServers();
-        break;
+
+        Json::Value system;
+        if (OrthancPlugins::RestApiGet(system, "/system", false))
+        {
+          bool hasExtendedFind = system.isMember(SYSTEM_CAPABILITIES) 
+                                      && system[SYSTEM_CAPABILITIES].isMember(SYSTEM_CAPABILITIES_HAS_EXTENDED_FIND)
+                                      && system[SYSTEM_CAPABILITIES][SYSTEM_CAPABILITIES_HAS_EXTENDED_FIND].asBool();
+          if (hasExtendedFind)
+          {
+            LOG(WARNING) << "Orthanc supports ExtendedFind.";
+            SetPluginCanUseExtendedFile(true);
+          }
+          else
+          {
+            LOG(WARNING) << "Orthanc does not support ExtendedFind.";
+          }
+        }
+
+      }; break;
 
       case OrthancPluginChangeType_StableSeries:
         CacheSeriesMetadata(resourceId);
--- a/Plugin/WadoRs.cpp	Wed Sep 04 12:56:30 2024 +0200
+++ b/Plugin/WadoRs.cpp	Mon Sep 16 11:20:07 2024 +0200
@@ -50,6 +50,17 @@
 static std::string instancesMainDicomTagsList;
 static boost::mutex mainDicomTagsListMutex;
 
+static bool pluginCanUseExtendedFind_ = false;
+
+void SetPluginCanUseExtendedFile(bool enable)
+{
+  pluginCanUseExtendedFind_ = enable;
+}
+
+bool CanUseExtendedFile()
+{
+  return pluginCanUseExtendedFind_;
+}
 
 static std::string GetResourceUri(Orthanc::ResourceType level,
                                   const std::string& publicId)
@@ -1348,15 +1359,13 @@
                                     const std::string& wadoBase)
 {
   const unsigned int workersCount =  OrthancPlugins::Configuration::GetMetadataWorkerThreadsCount();
-  const bool oneLargeQuery = false;  // we keep this code here for future use once we'll have optimized Orthanc API /series/.../instances?full to minimize the SQL queries
-                                // right now, it is faster to call /instances/..?full in each worker but, later, it should be more efficient with a large SQL query in Orthanc
 
   if (workersCount > 1 && mode == OrthancPlugins::MetadataMode_Full)
   {
     ChildrenMainDicomMaps instancesDicomMaps;
     std::string seriesDicomUid;
 
-    if (oneLargeQuery)
+    if (CanUseExtendedFile()) // in this case, /series/.../instances?full has been optimized to minimize the SQL queries
     {
       GetChildrenMainDicomTags(instancesDicomMaps, seriesDicomUid, Orthanc::ResourceType_Series, seriesOrthancId);
       for (ChildrenMainDicomMaps::const_iterator it = instancesDicomMaps.begin(); it != instancesDicomMaps.end(); ++it)
@@ -1382,7 +1391,7 @@
       instancesWorkers.push_back(boost::shared_ptr<boost::thread>(new boost::thread(InstanceWorkerThread, threadData)));
     }
 
-    if (oneLargeQuery)
+    if (CanUseExtendedFile())  // we must correct the bulkRoot
     {
       for (ChildrenMainDicomMaps::const_iterator i = instancesDicomMaps.begin(); i != instancesDicomMaps.end(); ++i)
       {
--- a/Plugin/WadoRs.h	Wed Sep 04 12:56:30 2024 +0200
+++ b/Plugin/WadoRs.h	Mon Sep 16 11:20:07 2024 +0200
@@ -102,4 +102,6 @@
                            const char* url,
                            const OrthancPluginHttpRequest* request);
 
-void SetPluginCanDownloadTranscodedFile(bool enable);
\ No newline at end of file
+void SetPluginCanDownloadTranscodedFile(bool enable);
+
+void SetPluginCanUseExtendedFile(bool enable);
\ No newline at end of file