# HG changeset patch # User Sebastien Jodogne # Date 1615224606 -3600 # Node ID e23bacd4fffc3a92d6f29ae3383ba69899ee5df2 # Parent 855e43bb293c14159469f87cb65c6bea78ab4dde clarifications in ServerIndex::Recycle() diff -r 855e43bb293c -r e23bacd4fffc OrthancServer/Sources/ServerIndex.cpp --- 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) {