# HG changeset patch # User Sebastien Jodogne # Date 1730830936 -3600 # Node ID 35d211bbe1014cbcc255ecf6e58c4a37d7a8133b # Parent aa09fbae4c0b7e813a39a49fbdab15fd93064315 refactoring StatelessDatabaseOperations::GetChildren() diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h --- 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 } /** diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp --- 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& result, + ResourceType level, const std::string& publicId) { - class Operations : public ReadOnlyOperationsT2&, 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& children = response.GetResourceByIndex(i).GetChildrenIdentifiers(childLevel); + + for (std::set::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 tmp; - transaction.GetChildrenInternalId(tmp, resource); - - tuple.get<0>().clear(); - - for (std::list::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); + } } diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/Database/StatelessDatabaseOperations.h --- 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& result, + ResourceType level, const std::string& publicId); void GetChildInstances(std::list& result, diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- 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& target, ServerIndex& index, + ResourceType level, const std::set& source) { target.clear(); @@ -3931,7 +3932,7 @@ it = source.begin(); it != source.end(); ++it) { std::list children; - index.GetChildren(children, *it); + index.GetChildren(children, level, *it); for (std::list::const_iterator child = children.begin(); child != children.end(); ++child) @@ -4018,11 +4019,11 @@ // Need to explore children std::set current; current.insert(*it); - + for (;;) { std::set children; - GetBulkChildren(children, index, current); + GetBulkChildren(children, index, type, current); type = GetChildResourceType(type); if (type == level) diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/OrthancWebDav.cpp --- 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 resources; try { - context_.GetIndex().GetChildren(resources, parentSeries_); + context_.GetIndex().GetChildren(resources, ResourceType_Series, parentSeries_); } catch (OrthancException&) { @@ -506,7 +506,7 @@ std::list 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) { } diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/ServerJobs/ArchiveJob.cpp --- 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 children; - index.GetChildren(children, it->first); + index.GetChildren(children, GetResourceLevel(level_), it->first); std::unique_ptr child(new ArchiveIndex(GetChildResourceType(level_))); diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp --- 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 instances; - GetContext().GetIndex().GetChildren(instances, series); + GetContext().GetIndex().GetChildren(instances, ResourceType_Series, series); for (std::list::const_iterator it = instances.begin(); it != instances.end(); ++it) @@ -69,7 +69,7 @@ else { std::list series; - GetContext().GetIndex().GetChildren(series, study); + GetContext().GetIndex().GetChildren(series, ResourceType_Study, study); for (std::list::const_iterator it = series.begin(); it != series.end(); ++it) diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp --- 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 instances; - GetContext().GetIndex().GetChildren(instances, series); + GetContext().GetIndex().GetChildren(instances, ResourceType_Series, series); for (std::list::const_iterator it = instances.begin(); it != instances.end(); ++it) diff -r aa09fbae4c0b -r 35d211bbe101 OrthancServer/Sources/SliceOrdering.cpp --- 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 instancesId; - index_.GetChildren(instancesId, seriesId_); + index_.GetChildren(instancesId, ResourceType_Series, seriesId_); instances_.reserve(instancesId.size()); for (std::list::const_iterator