Mercurial > hg > orthanc
diff OrthancServer/Sources/ServerIndex.cpp @ 4575:e23bacd4fffc db-changes
clarifications in ServerIndex::Recycle()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Mar 2021 18:30:06 +0100 |
parents | 855e43bb293c |
children | f6cd49af7526 |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerIndex.cpp Mon Mar 08 18:15:26 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.cpp Mon Mar 08 18:30:06 2021 +0100 @@ -1112,48 +1112,55 @@ void ServerIndex::Recycle(uint64_t instanceSize, const std::string& newPatientId) { - if (!IsRecyclingNeeded(instanceSize)) - { - return; - } - - // Check whether other DICOM instances from this patient are - // already stored - int64_t patientToAvoid; - ResourceType type; - bool hasPatientToAvoid = db_.LookupResource(patientToAvoid, type, newPatientId); - - if (hasPatientToAvoid && type != ResourceType_Patient) + if (IsRecyclingNeeded(instanceSize)) { - throw OrthancException(ErrorCode_InternalError); - } - - // Iteratively select patient to remove until there is enough - // space in the DICOM store - int64_t patientToRecycle; - while (true) - { - // If other instances of this patient are already in the store, - // we must avoid to recycle them - bool ok = hasPatientToAvoid ? - db_.SelectPatientToRecycle(patientToRecycle, patientToAvoid) : - db_.SelectPatientToRecycle(patientToRecycle); + // Check whether other DICOM instances from this patient are + // already stored + int64_t patientToAvoid; + bool hasPatientToAvoid; + + if (newPatientId.empty()) + { + hasPatientToAvoid = false; + } + else + { + ResourceType type; + hasPatientToAvoid = db_.LookupResource(patientToAvoid, type, newPatientId); + if (type != ResourceType_Patient) + { + throw OrthancException(ErrorCode_InternalError); + } + } + + // Iteratively select patient to remove until there is enough + // space in the DICOM store + int64_t patientToRecycle; + while (true) + { + // If other instances of this patient are already in the store, + // we must avoid to recycle them + bool ok = (hasPatientToAvoid ? + db_.SelectPatientToRecycle(patientToRecycle, patientToAvoid) : + db_.SelectPatientToRecycle(patientToRecycle)); - if (!ok) - { - throw OrthancException(ErrorCode_FullStorage); - } + if (!ok) + { + throw OrthancException(ErrorCode_FullStorage); + } - LOG(TRACE) << "Recycling one patient"; - db_.DeleteResource(patientToRecycle); - - if (!IsRecyclingNeeded(instanceSize)) - { - // OK, we're done - break; + LOG(TRACE) << "Recycling one patient"; + db_.DeleteResource(patientToRecycle); + + if (!IsRecyclingNeeded(instanceSize)) + { + // OK, we're done + break; + } } } - } + } + void ServerIndex::SetMaximumPatientCount(unsigned int count) {