changeset 5863:35d211bbe101 find-refactoring tip

refactoring StatelessDatabaseOperations::GetChildren()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Nov 2024 19:22:16 +0100
parents aa09fbae4c0b
children
files OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/Sources/ServerJobs/ArchiveJob.cpp OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp OrthancServer/Sources/SliceOrdering.cpp
diffstat 9 files changed, 35 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h	Tue Nov 05 19:22:16 2024 +0100
@@ -102,8 +102,8 @@
 
     virtual bool HasIntegratedFind() const ORTHANC_OVERRIDE
     {
-      return true;   // => This uses specialized SQL commands
-      //return false;   // => This uses Compatibility/GenericFind
+      //return true;   // => This uses specialized SQL commands
+      return false;   // => This uses Compatibility/GenericFind
     }
 
     /**
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Nov 05 19:22:16 2024 +0100
@@ -926,43 +926,29 @@
 
 
   void StatelessDatabaseOperations::GetChildren(std::list<std::string>& result,
+                                                ResourceType level,
                                                 const std::string& publicId)
   {
-    class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, const std::string&>
+    const ResourceType childLevel = GetChildResourceType(level);
+
+    FindRequest request(level);
+    request.SetOrthancId(level, publicId);
+    request.GetChildrenSpecification(childLevel).SetRetrieveIdentifiers(true);
+
+    FindResponse response;
+    ExecuteFind(response, request);
+
+    result.clear();
+
+    for (size_t i = 0; i < response.GetSize(); i++)
     {
-    public:
-      virtual void ApplyTuple(ReadOnlyTransaction& transaction,
-                              const Tuple& tuple) ORTHANC_OVERRIDE
+      const std::set<std::string>& children = response.GetResourceByIndex(i).GetChildrenIdentifiers(childLevel);
+
+      for (std::set<std::string>::const_iterator it = children.begin(); it != children.end(); ++it)
       {
-        ResourceType type;
-        int64_t resource;
-        if (!transaction.LookupResource(resource, type, tuple.get<1>()))
-        {
-          throw OrthancException(ErrorCode_UnknownResource);
-        }
-        else if (type == ResourceType_Instance)
-        {
-          // An instance cannot have a child
-          throw OrthancException(ErrorCode_BadParameterType);
-        }
-        else
-        {
-          std::list<int64_t> tmp;
-          transaction.GetChildrenInternalId(tmp, resource);
-
-          tuple.get<0>().clear();
-
-          for (std::list<int64_t>::const_iterator 
-                 it = tmp.begin(); it != tmp.end(); ++it)
-          {
-            tuple.get<0>().push_back(transaction.GetPublicId(*it));
-          }
-        }
+        result.push_back(*it);
       }
-    };
-    
-    Operations operations;
-    operations.Apply(*this, result, publicId);
+    }
   }
 
 
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Tue Nov 05 19:22:16 2024 +0100
@@ -569,6 +569,7 @@
     bool IsProtectedPatient(const std::string& publicId);
 
     void GetChildren(std::list<std::string>& result,
+                     ResourceType level,
                      const std::string& publicId);
 
     void GetChildInstances(std::list<std::string>& result,
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Nov 05 19:22:16 2024 +0100
@@ -3923,6 +3923,7 @@
 
   static void GetBulkChildren(std::set<std::string>& target,
                               ServerIndex& index,
+                              ResourceType level,
                               const std::set<std::string>& source)
   {
     target.clear();
@@ -3931,7 +3932,7 @@
            it = source.begin(); it != source.end(); ++it)
     {
       std::list<std::string> children;
-      index.GetChildren(children, *it);
+      index.GetChildren(children, level, *it);
 
       for (std::list<std::string>::const_iterator
              child = children.begin(); child != children.end(); ++child)
@@ -4018,11 +4019,11 @@
               // Need to explore children
               std::set<std::string> current;
               current.insert(*it);
-              
+
               for (;;)
               {
                 std::set<std::string> children;
-                GetBulkChildren(children, index, current);
+                GetBulkChildren(children, index, type, current);
 
                 type = GetChildResourceType(type);
                 if (type == level)
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Tue Nov 05 19:22:16 2024 +0100
@@ -437,7 +437,7 @@
         std::list<std::string> resources;
         try
         {
-          context_.GetIndex().GetChildren(resources, parentSeries_);
+          context_.GetIndex().GetChildren(resources, ResourceType_Series, parentSeries_);
         }
         catch (OrthancException&)
         {
@@ -506,7 +506,7 @@
         std::list<std::string> resources;
         try
         {
-          context_.GetIndex().GetChildren(resources, parentSeries_);
+          context_.GetIndex().GetChildren(resources, ResourceType_Series, parentSeries_);
         }
         catch (OrthancException&)
         {
@@ -824,6 +824,7 @@
   class OrthancWebDav::SingleDicomResource : public ListOfResources
   {
   private:
+    ResourceType parentLevel_;
     std::string  parentId_;
     
   protected: 
@@ -831,7 +832,7 @@
     {
       try
       {
-        GetContext().GetIndex().GetChildren(resources, parentId_);
+        GetContext().GetIndex().GetChildren(resources, parentLevel_, parentId_);
       }
       catch (OrthancException&)
       {
@@ -863,6 +864,7 @@
                         const std::string& parentId,
                         const Templates& templates) :
       ListOfResources(context, level, templates),
+      parentLevel_(GetParentResourceType(level)),
       parentId_(parentId)
     {
     }
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Tue Nov 05 19:22:16 2024 +0100
@@ -622,7 +622,7 @@
         {
           // This is resource is marked for expansion
           std::list<std::string> children;
-          index.GetChildren(children, it->first);
+          index.GetChildren(children, GetResourceLevel(level_), it->first);
 
           std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_)));
 
--- a/OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp	Tue Nov 05 19:22:16 2024 +0100
@@ -49,7 +49,7 @@
 
     // Add all the instances of the series as to be processed
     std::list<std::string> instances;
-    GetContext().GetIndex().GetChildren(instances, series);
+    GetContext().GetIndex().GetChildren(instances, ResourceType_Series, series);
 
     for (std::list<std::string>::const_iterator
            it = instances.begin(); it != instances.end(); ++it)
@@ -69,7 +69,7 @@
     else
     {
       std::list<std::string> series;
-      GetContext().GetIndex().GetChildren(series, study);
+      GetContext().GetIndex().GetChildren(series, ResourceType_Study, study);
 
       for (std::list<std::string>::const_iterator
              it = series.begin(); it != series.end(); ++it)
--- a/OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp	Tue Nov 05 19:22:16 2024 +0100
@@ -213,7 +213,7 @@
 
       // Add all the instances of the series as to be processed
       std::list<std::string> instances;
-      GetContext().GetIndex().GetChildren(instances, series);
+      GetContext().GetIndex().GetChildren(instances, ResourceType_Series, series);
 
       for (std::list<std::string>::const_iterator
              it = instances.begin(); it != instances.end(); ++it)
--- a/OrthancServer/Sources/SliceOrdering.cpp	Tue Nov 05 18:54:21 2024 +0100
+++ b/OrthancServer/Sources/SliceOrdering.cpp	Tue Nov 05 19:22:16 2024 +0100
@@ -297,7 +297,7 @@
   void SliceOrdering::CreateInstances()
   {
     std::list<std::string> instancesId;
-    index_.GetChildren(instancesId, seriesId_);
+    index_.GetChildren(instancesId, ResourceType_Series, seriesId_);
 
     instances_.reserve(instancesId.size());
     for (std::list<std::string>::const_iterator