Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 5048:22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 29 Jun 2022 13:15:20 +0200 |
parents | 6fed78e13233 |
children | d4e5ca0c9307 |
comparison
equal
deleted
inserted
replaced
5047:207f259c41c5 | 5048:22966345eaba |
---|---|
486 | 486 |
487 | 487 |
488 void ServerContext::RemoveFile(const std::string& fileUuid, | 488 void ServerContext::RemoveFile(const std::string& fileUuid, |
489 FileContentType type) | 489 FileContentType type) |
490 { | 490 { |
491 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 491 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
492 accessor.Remove(fileUuid, type); | 492 accessor.Remove(fileUuid, type); |
493 } | 493 } |
494 | 494 |
495 | 495 |
496 ServerContext::StoreResult ServerContext::StoreAfterTranscoding(std::string& resultPublicId, | 496 ServerContext::StoreResult ServerContext::StoreAfterTranscoding(std::string& resultPublicId, |
531 std::set<DicomTag> allMainDicomTags = DicomMap::GetAllMainDicomTags(); | 531 std::set<DicomTag> allMainDicomTags = DicomMap::GetAllMainDicomTags(); |
532 | 532 |
533 try | 533 try |
534 { | 534 { |
535 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); | 535 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); |
536 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 536 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
537 | 537 |
538 DicomInstanceHasher hasher(summary); | 538 DicomInstanceHasher hasher(summary); |
539 resultPublicId = hasher.HashInstance(); | 539 resultPublicId = hasher.HashInstance(); |
540 | 540 |
541 Json::Value dicomAsJson; | 541 Json::Value dicomAsJson; |
849 { | 849 { |
850 throw OrthancException(ErrorCode_UnknownResource); | 850 throw OrthancException(ErrorCode_UnknownResource); |
851 } | 851 } |
852 else | 852 else |
853 { | 853 { |
854 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 854 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
855 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); | 855 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); |
856 } | 856 } |
857 } | 857 } |
858 | 858 |
859 | 859 |
879 return; | 879 return; |
880 } | 880 } |
881 | 881 |
882 std::string content; | 882 std::string content; |
883 | 883 |
884 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 884 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
885 accessor.Read(content, attachment); | 885 accessor.Read(content, attachment); |
886 | 886 |
887 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), | 887 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), |
888 content.size(), attachmentType, compression, storeMD5_); | 888 content.size(), attachmentType, compression, storeMD5_); |
889 | 889 |
935 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData)) | 935 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData)) |
936 { | 936 { |
937 std::string dicom; | 937 std::string dicom; |
938 | 938 |
939 { | 939 { |
940 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 940 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
941 accessor.Read(dicom, attachment); | 941 accessor.Read(dicom, attachment); |
942 } | 942 } |
943 | 943 |
944 ParsedDicomFile parsed(dicom); | 944 ParsedDicomFile parsed(dicom); |
945 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); | 945 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); |
1001 **/ | 1001 **/ |
1002 | 1002 |
1003 std::string dicom; | 1003 std::string dicom; |
1004 | 1004 |
1005 { | 1005 { |
1006 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 1006 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
1007 accessor.ReadStartRange(dicom, attachment.GetUuid(), FileContentType_Dicom, pixelDataOffset); | 1007 accessor.ReadStartRange(dicom, attachment.GetUuid(), FileContentType_Dicom, pixelDataOffset); |
1008 } | 1008 } |
1009 | 1009 |
1010 assert(dicom.size() == pixelDataOffset); | 1010 assert(dicom.size() == pixelDataOffset); |
1011 ParsedDicomFile parsed(dicom); | 1011 ParsedDicomFile parsed(dicom); |
1024 **/ | 1024 **/ |
1025 | 1025 |
1026 std::string dicomAsJson; | 1026 std::string dicomAsJson; |
1027 | 1027 |
1028 { | 1028 { |
1029 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 1029 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
1030 accessor.Read(dicomAsJson, attachment); | 1030 accessor.Read(dicomAsJson, attachment); |
1031 } | 1031 } |
1032 | 1032 |
1033 if (!Toolbox::ReadJson(result, dicomAsJson)) | 1033 if (!Toolbox::ReadJson(result, dicomAsJson)) |
1034 { | 1034 { |
1130 { | 1130 { |
1131 try | 1131 try |
1132 { | 1132 { |
1133 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s); | 1133 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s); |
1134 | 1134 |
1135 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 1135 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
1136 | 1136 |
1137 accessor.ReadStartRange(dicom, attachment.GetUuid(), attachment.GetContentType(), pixelDataOffset); | 1137 accessor.ReadStartRange(dicom, attachment.GetUuid(), attachment.GetContentType(), pixelDataOffset); |
1138 assert(dicom.size() == pixelDataOffset); | 1138 assert(dicom.size() == pixelDataOffset); |
1139 | 1139 |
1140 return true; // Success | 1140 return true; // Success |
1151 | 1151 |
1152 void ServerContext::ReadAttachment(std::string& result, | 1152 void ServerContext::ReadAttachment(std::string& result, |
1153 int64_t& revision, | 1153 int64_t& revision, |
1154 const std::string& instancePublicId, | 1154 const std::string& instancePublicId, |
1155 FileContentType content, | 1155 FileContentType content, |
1156 bool uncompressIfNeeded) | 1156 bool uncompressIfNeeded, |
1157 bool skipCache) | |
1157 { | 1158 { |
1158 FileInfo attachment; | 1159 FileInfo attachment; |
1159 if (!index_.LookupAttachment(attachment, revision, instancePublicId, content)) | 1160 if (!index_.LookupAttachment(attachment, revision, instancePublicId, content)) |
1160 { | 1161 { |
1161 throw OrthancException(ErrorCode_InternalError, | 1162 throw OrthancException(ErrorCode_InternalError, |
1164 } | 1165 } |
1165 | 1166 |
1166 assert(attachment.GetContentType() == content); | 1167 assert(attachment.GetContentType() == content); |
1167 | 1168 |
1168 { | 1169 { |
1169 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 1170 StorageCache* cache = NULL; |
1171 | |
1172 if (!skipCache) | |
1173 { | |
1174 cache = &storageCache_; | |
1175 } | |
1176 | |
1177 StorageAccessor accessor(area_, cache, GetMetricsRegistry()); | |
1170 | 1178 |
1171 if (uncompressIfNeeded) | 1179 if (uncompressIfNeeded) |
1172 { | 1180 { |
1173 accessor.Read(result, attachment); | 1181 accessor.Read(result, attachment); |
1174 } | 1182 } |
1264 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; | 1272 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; |
1265 | 1273 |
1266 // TODO Should we use "gzip" instead? | 1274 // TODO Should we use "gzip" instead? |
1267 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); | 1275 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); |
1268 | 1276 |
1269 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | 1277 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); |
1270 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); | 1278 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); |
1271 | 1279 |
1272 try | 1280 try |
1273 { | 1281 { |
1274 StoreStatus status = index_.AddAttachment( | 1282 StoreStatus status = index_.AddAttachment( |