Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPluginDatabase.cpp @ 3076:8bc2cb1335f4 db-changes
OrthancPluginDatabase::ApplyLookupResources() using fast lookup
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 02 Jan 2019 19:04:15 +0100 |
parents | ead8576a02ef |
children | 147497152ce3 |
comparison
equal
deleted
inserted
replaced
3075:ead8576a02ef | 3076:8bc2cb1335f4 |
---|---|
131 | 131 |
132 answerDicomMap_ = NULL; | 132 answerDicomMap_ = NULL; |
133 answerChanges_ = NULL; | 133 answerChanges_ = NULL; |
134 answerExportedResources_ = NULL; | 134 answerExportedResources_ = NULL; |
135 answerDone_ = NULL; | 135 answerDone_ = NULL; |
136 answerMatchingResources_ = NULL; | |
137 answerMatchingInstances_ = NULL; | |
136 } | 138 } |
137 | 139 |
138 | 140 |
139 void OrthancPluginDatabase::ForwardAnswers(std::list<int64_t>& target) | 141 void OrthancPluginDatabase::ForwardAnswers(std::list<int64_t>& target) |
140 { | 142 { |
222 const OrthancPluginDatabaseExtensions* extensions, | 224 const OrthancPluginDatabaseExtensions* extensions, |
223 size_t extensionsSize, | 225 size_t extensionsSize, |
224 void *payload) : | 226 void *payload) : |
225 library_(library), | 227 library_(library), |
226 errorDictionary_(errorDictionary), | 228 errorDictionary_(errorDictionary), |
227 type_(_OrthancPluginDatabaseAnswerType_None), | |
228 backend_(backend), | 229 backend_(backend), |
229 payload_(payload), | 230 payload_(payload), |
230 listener_(NULL), | 231 listener_(NULL) |
231 answerDicomMap_(NULL), | 232 { |
232 answerChanges_(NULL), | 233 ResetAnswers(); |
233 answerExportedResources_(NULL), | 234 |
234 answerDone_(NULL) | |
235 { | |
236 memset(&extensions_, 0, sizeof(extensions_)); | 235 memset(&extensions_, 0, sizeof(extensions_)); |
237 | 236 |
238 size_t size = sizeof(extensions_); | 237 size_t size = sizeof(extensions_); |
239 if (extensionsSize < size) | 238 if (extensionsSize < size) |
240 { | 239 { |
241 size = extensionsSize; // Not all the extensions are available | 240 size = extensionsSize; // Not all the extensions are available |
242 } | 241 } |
243 | 242 |
244 memcpy(&extensions_, extensions, size); | 243 memcpy(&extensions_, extensions, size); |
244 | |
245 if (extensions_.lookupResources == NULL) | |
246 { | |
247 LOG(WARNING) << "Performance warning in index plugin: Fast lookup is not available"; | |
248 } | |
245 } | 249 } |
246 | 250 |
247 | 251 |
248 void OrthancPluginDatabase::Open() | 252 void OrthancPluginDatabase::Open() |
249 { | 253 { |
956 break; | 960 break; |
957 | 961 |
958 case _OrthancPluginDatabaseAnswerType_ExportedResource: | 962 case _OrthancPluginDatabaseAnswerType_ExportedResource: |
959 assert(answerExportedResources_ != NULL); | 963 assert(answerExportedResources_ != NULL); |
960 answerExportedResources_->clear(); | 964 answerExportedResources_->clear(); |
965 break; | |
966 | |
967 case _OrthancPluginDatabaseAnswerType_MatchingResource: | |
968 assert(answerMatchingResources_ != NULL); | |
969 answerMatchingResources_->clear(); | |
970 | |
971 if (answerMatchingInstances_ != NULL) | |
972 { | |
973 answerMatchingInstances_->clear(); | |
974 } | |
975 | |
961 break; | 976 break; |
962 | 977 |
963 default: | 978 default: |
964 throw OrthancException(ErrorCode_DatabasePlugin, | 979 throw OrthancException(ErrorCode_DatabasePlugin, |
965 "Unhandled type of answer for custom index plugin: " + | 980 "Unhandled type of answer for custom index plugin: " + |
1086 } | 1101 } |
1087 | 1102 |
1088 break; | 1103 break; |
1089 } | 1104 } |
1090 | 1105 |
1106 case _OrthancPluginDatabaseAnswerType_MatchingResource: | |
1107 { | |
1108 const OrthancPluginMatchingResource& match = | |
1109 *reinterpret_cast<const OrthancPluginMatchingResource*>(answer.valueGeneric); | |
1110 | |
1111 if (match.resourceId == NULL) | |
1112 { | |
1113 throw OrthancException(ErrorCode_DatabasePlugin); | |
1114 } | |
1115 | |
1116 assert(answerMatchingResources_ != NULL); | |
1117 answerMatchingResources_->push_back(match.resourceId); | |
1118 | |
1119 if (answerMatchingInstances_ != NULL) | |
1120 { | |
1121 if (match.someInstanceId == NULL) | |
1122 { | |
1123 throw OrthancException(ErrorCode_DatabasePlugin); | |
1124 } | |
1125 | |
1126 answerMatchingInstances_->push_back(match.someInstanceId); | |
1127 } | |
1128 | |
1129 break; | |
1130 } | |
1131 | |
1091 default: | 1132 default: |
1092 throw OrthancException(ErrorCode_DatabasePlugin, | 1133 throw OrthancException(ErrorCode_DatabasePlugin, |
1093 "Unhandled type of answer for custom index plugin: " + | 1134 "Unhandled type of answer for custom index plugin: " + |
1094 boost::lexical_cast<std::string>(answer.type)); | 1135 boost::lexical_cast<std::string>(answer.type)); |
1095 } | 1136 } |
1116 ResourceType queryLevel, | 1157 ResourceType queryLevel, |
1117 size_t limit) | 1158 size_t limit) |
1118 { | 1159 { |
1119 if (extensions_.lookupResources == NULL) | 1160 if (extensions_.lookupResources == NULL) |
1120 { | 1161 { |
1162 // Fallback to compatibility mode | |
1121 CompatibilityDatabaseWrapper::ApplyLookupResources | 1163 CompatibilityDatabaseWrapper::ApplyLookupResources |
1122 (resourcesId, instancesId, lookup, queryLevel, limit); | 1164 (resourcesId, instancesId, lookup, queryLevel, limit); |
1123 } | 1165 } |
1124 else | 1166 else |
1125 { | 1167 { |
1168 std::vector<OrthancPluginDatabaseConstraint> constraints; | |
1169 std::vector< std::vector<const char*> > constraintsValues; | |
1170 | |
1171 constraints.resize(lookup.size()); | |
1172 constraintsValues.resize(lookup.size()); | |
1173 | |
1174 for (size_t i = 0; i < lookup.size(); i++) | |
1175 { | |
1176 lookup[i].EncodeForPlugins(constraints[i], constraintsValues[i]); | |
1177 } | |
1178 | |
1179 answerMatchingResources_ = &resourcesId; | |
1180 answerMatchingInstances_ = instancesId; | |
1181 | |
1126 ResetAnswers(); | 1182 ResetAnswers(); |
1183 | |
1184 CheckSuccess(extensions_.lookupResources(GetContext(), payload_, lookup.size(), | |
1185 (lookup.empty() ? NULL : &constraints[0]), | |
1186 Plugins::Convert(queryLevel), | |
1187 limit, (instancesId == NULL ? 0 : 1))); | |
1127 } | 1188 } |
1128 } | 1189 } |
1129 | 1190 |
1130 | 1191 |
1131 void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& result, | 1192 void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& result, |