comparison OrthancServer/ServerContext.cpp @ 3012:af1530b45290

Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Dec 2018 17:54:06 +0100
parents 8265a6b56100
children abe49ca61cd5
comparison
equal deleted inserted replaced
3010:9f859a18cbc2 3012:af1530b45290
786 assert(resources.size() == instances.size()); 786 assert(resources.size() == instances.size());
787 787
788 size_t countResults = 0; 788 size_t countResults = 0;
789 size_t skipped = 0; 789 size_t skipped = 0;
790 bool complete = true; 790 bool complete = true;
791 791
792 for (size_t i = 0; i < instances.size(); i++) 792 for (size_t i = 0; i < instances.size(); i++)
793 { 793 {
794 // TODO - Don't read the full JSON from the disk if only "main 794 // Optimization in Orthanc 1.5.1 - Don't read the full JSON from
795 // DICOM tags" are to be returned 795 // the disk if only "main DICOM tags" are to be returned
796 Json::Value dicom; 796
797 ReadDicomAsJson(dicom, instances[i]); 797 std::auto_ptr<Json::Value> dicomAsJson;
798
799 bool hasOnlyMainDicomTags;
800 DicomMap dicom;
801
802 if (lookup.HasOnlyMainDicomTags() &&
803 GetIndex().GetAllMainDicomTags(dicom, instances[i]))
804 {
805 // Case (1): The main DICOM tags, as stored in the database,
806 // are sufficient to look for match
807 hasOnlyMainDicomTags = true;
808 }
809 else
810 {
811 // Case (2): Need to read the "DICOM-as-JSON" attachment from
812 // the storage area
813 dicomAsJson.reset(new Json::Value);
814 ReadDicomAsJson(*dicomAsJson, instances[i]);
815
816 dicom.FromDicomAsJson(*dicomAsJson);
817
818 // This map contains the entire JSON, i.e. more than the main DICOM tags
819 hasOnlyMainDicomTags = false;
820 }
798 821
799 if (lookup.IsMatch(dicom)) 822 if (lookup.IsMatch(dicom))
800 { 823 {
801 if (skipped < since) 824 if (skipped < since)
802 { 825 {
809 complete = false; 832 complete = false;
810 break; 833 break;
811 } 834 }
812 else 835 else
813 { 836 {
814 visitor.Visit(resources[i], instances[i], dicom); 837 if (dicomAsJson.get() == NULL &&
838 visitor.IsDicomAsJsonNeeded())
839 {
840 dicomAsJson.reset(new Json::Value);
841 ReadDicomAsJson(*dicomAsJson, instances[i]);
842 }
843
844 if (hasOnlyMainDicomTags)
845 {
846 // This is Case (1): The variable "dicom" only contains the main DICOM tags
847 visitor.Visit(resources[i], instances[i], dicom, dicomAsJson.get());
848 }
849 else
850 {
851 // Remove the non-main DICOM tags from "dicom" if Case (2)
852 // was used, for consistency with Case (1)
853
854 DicomMap mainDicomTags;
855 mainDicomTags.ExtractMainDicomTags(dicom);
856 visitor.Visit(resources[i], instances[i], mainDicomTags, dicomAsJson.get());
857 }
858
815 countResults ++; 859 countResults ++;
816 } 860 }
817 } 861 }
818 } 862 }
819 863