Mercurial > hg > orthanc
changeset 5892:e92f196afd04 find-refactoring
avoid starting trivial transactions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 30 Nov 2024 21:33:10 +0100 |
parents | 53e7a0c0648f |
children | 1c23f71858a2 |
files | OrthancServer/Sources/Database/Compatibility/GenericFind.cpp OrthancServer/Sources/Database/FindRequest.cpp OrthancServer/Sources/Database/FindRequest.h OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp |
diffstat | 4 files changed, 60 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Sat Nov 30 21:20:33 2024 +0100 +++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Sat Nov 30 21:33:10 2024 +0100 @@ -33,14 +33,6 @@ { namespace Compatibility { - static bool IsRequestWithoutContraint(const FindRequest& request) - { - return (request.GetDicomTagConstraints().IsEmpty() && - request.GetMetadataConstraintsCount() == 0 && - request.GetLabels().empty() && - request.GetOrdering().empty()); - } - static void GetChildren(std::list<int64_t>& target, IDatabaseWrapper::ITransaction& transaction, const std::list<int64_t>& resources) @@ -129,7 +121,7 @@ throw OrthancException(ErrorCode_NotImplemented, "The database backend doesn't support ordering"); } - if (IsRequestWithoutContraint(request) && + if (!request.HasConstraints() && !request.GetOrthancIdentifiers().HasPatientId() && !request.GetOrthancIdentifiers().HasStudyId() && !request.GetOrthancIdentifiers().HasSeriesId() && @@ -161,47 +153,7 @@ } } } - else if (IsRequestWithoutContraint(request) && - request.GetLevel() == ResourceType_Patient && - request.GetOrthancIdentifiers().HasPatientId() && - !request.GetOrthancIdentifiers().HasStudyId() && - !request.GetOrthancIdentifiers().HasSeriesId() && - !request.GetOrthancIdentifiers().HasInstanceId()) - { - // TODO-FIND: This is a trivial case for which no transaction is needed - identifiers.push_back(request.GetOrthancIdentifiers().GetPatientId()); - } - else if (IsRequestWithoutContraint(request) && - request.GetLevel() == ResourceType_Study && - !request.GetOrthancIdentifiers().HasPatientId() && - request.GetOrthancIdentifiers().HasStudyId() && - !request.GetOrthancIdentifiers().HasSeriesId() && - !request.GetOrthancIdentifiers().HasInstanceId()) - { - // TODO-FIND: This is a trivial case for which no transaction is needed - identifiers.push_back(request.GetOrthancIdentifiers().GetStudyId()); - } - else if (IsRequestWithoutContraint(request) && - request.GetLevel() == ResourceType_Series && - !request.GetOrthancIdentifiers().HasPatientId() && - !request.GetOrthancIdentifiers().HasStudyId() && - request.GetOrthancIdentifiers().HasSeriesId() && - !request.GetOrthancIdentifiers().HasInstanceId()) - { - // TODO-FIND: This is a trivial case for which no transaction is needed - identifiers.push_back(request.GetOrthancIdentifiers().GetSeriesId()); - } - else if (IsRequestWithoutContraint(request) && - request.GetLevel() == ResourceType_Instance && - !request.GetOrthancIdentifiers().HasPatientId() && - !request.GetOrthancIdentifiers().HasStudyId() && - !request.GetOrthancIdentifiers().HasSeriesId() && - request.GetOrthancIdentifiers().HasInstanceId()) - { - // TODO-FIND: This is a trivial case for which no transaction is needed - identifiers.push_back(request.GetOrthancIdentifiers().GetInstanceId()); - } - else if (IsRequestWithoutContraint(request) && + else if (!request.HasConstraints() && (request.GetLevel() == ResourceType_Study || request.GetLevel() == ResourceType_Series || request.GetLevel() == ResourceType_Instance) && @@ -213,7 +165,7 @@ GetChildrenIdentifiers(identifiers, transaction_, compatibilityTransaction_, request.GetOrthancIdentifiers(), ResourceType_Patient, request.GetLevel()); } - else if (IsRequestWithoutContraint(request) && + else if (!request.HasConstraints() && (request.GetLevel() == ResourceType_Series || request.GetLevel() == ResourceType_Instance) && !request.GetOrthancIdentifiers().HasPatientId() && @@ -224,7 +176,7 @@ GetChildrenIdentifiers(identifiers, transaction_, compatibilityTransaction_, request.GetOrthancIdentifiers(), ResourceType_Study, request.GetLevel()); } - else if (IsRequestWithoutContraint(request) && + else if (!request.HasConstraints() && request.GetLevel() == ResourceType_Instance && !request.GetOrthancIdentifiers().HasPatientId() && !request.GetOrthancIdentifiers().HasStudyId() &&
--- a/OrthancServer/Sources/Database/FindRequest.cpp Sat Nov 30 21:20:33 2024 +0100 +++ b/OrthancServer/Sources/Database/FindRequest.cpp Sat Nov 30 21:33:10 2024 +0100 @@ -282,4 +282,12 @@ return retrieveOneInstanceMetadataAndAttachments_; } } + + bool FindRequest::HasConstraints() const + { + return (!GetDicomTagConstraints().IsEmpty() || + GetMetadataConstraintsCount() != 0 || + !GetLabels().empty() || + !GetOrdering().empty()); + } }
--- a/OrthancServer/Sources/Database/FindRequest.h Sat Nov 30 21:20:33 2024 +0100 +++ b/OrthancServer/Sources/Database/FindRequest.h Sat Nov 30 21:33:10 2024 +0100 @@ -446,5 +446,7 @@ void SetRetrieveOneInstanceMetadataAndAttachments(bool retrieve); bool IsRetrieveOneInstanceMetadataAndAttachments() const; + + bool HasConstraints() const; }; }
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Sat Nov 30 21:20:33 2024 +0100 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Sat Nov 30 21:33:10 2024 +0100 @@ -3281,8 +3281,52 @@ **/ std::list<std::string> identifiers; - FindStage find; - find.Apply(*this, identifiers, capabilities, request); + if (!request.HasConstraints() && + request.GetLevel() == ResourceType_Patient && + request.GetOrthancIdentifiers().HasPatientId() && + !request.GetOrthancIdentifiers().HasStudyId() && + !request.GetOrthancIdentifiers().HasSeriesId() && + !request.GetOrthancIdentifiers().HasInstanceId()) + { + // This is a trivial case for which no transaction is needed + identifiers.push_back(request.GetOrthancIdentifiers().GetPatientId()); + } + else if (!request.HasConstraints() && + request.GetLevel() == ResourceType_Study && + !request.GetOrthancIdentifiers().HasPatientId() && + request.GetOrthancIdentifiers().HasStudyId() && + !request.GetOrthancIdentifiers().HasSeriesId() && + !request.GetOrthancIdentifiers().HasInstanceId()) + { + // This is a trivial case for which no transaction is needed + identifiers.push_back(request.GetOrthancIdentifiers().GetStudyId()); + } + else if (!request.HasConstraints() && + request.GetLevel() == ResourceType_Series && + !request.GetOrthancIdentifiers().HasPatientId() && + !request.GetOrthancIdentifiers().HasStudyId() && + request.GetOrthancIdentifiers().HasSeriesId() && + !request.GetOrthancIdentifiers().HasInstanceId()) + { + // This is a trivial case for which no transaction is needed + identifiers.push_back(request.GetOrthancIdentifiers().GetSeriesId()); + } + else if (!request.HasConstraints() && + request.GetLevel() == ResourceType_Instance && + !request.GetOrthancIdentifiers().HasPatientId() && + !request.GetOrthancIdentifiers().HasStudyId() && + !request.GetOrthancIdentifiers().HasSeriesId() && + request.GetOrthancIdentifiers().HasInstanceId()) + { + // This is a trivial case for which no transaction is needed + identifiers.push_back(request.GetOrthancIdentifiers().GetInstanceId()); + } + else + { + // Non-trival case, a transaction is needed + FindStage find; + find.Apply(*this, identifiers, capabilities, request); + } ExpandStage expand;