comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 574:58fce5aebb31 find-refactoring tip

fix
author Alain Mazy <am@orthanc.team>
date Fri, 27 Sep 2024 18:49:10 +0200
parents 523241efee57
children
comparison
equal deleted inserted replaced
573:523241efee57 574:58fce5aebb31
163 << "to speed up wildcard searches. This may take several minutes"; 163 << "to speed up wildcard searches. This may take several minutes";
164 needToRunUpgradeV1toV2 = true; 164 needToRunUpgradeV1toV2 = true;
165 } 165 }
166 166
167 int property = 0; 167 int property = 0;
168 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, 168 // these extensions are not installed anymore from v6.0 of the plugin (but the plugin is fast to compute the size and count the resources)
169 Orthanc::GlobalProperty_HasFastCountResources) || 169 // if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER,
170 property != 1) 170 // Orthanc::GlobalProperty_HasFastCountResources) ||
171 { 171 // property != 1)
172 needToRunUpgradeV1toV2 = true; 172 // {
173 } 173 // needToRunUpgradeV1toV2 = true;
174 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, 174 // }
175 Orthanc::GlobalProperty_GetTotalSizeIsFast) || 175 // if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER,
176 property != 1) 176 // Orthanc::GlobalProperty_GetTotalSizeIsFast) ||
177 { 177 // property != 1)
178 needToRunUpgradeV1toV2 = true; 178 // {
179 } 179 // needToRunUpgradeV1toV2 = true;
180 // }
180 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, 181 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER,
181 Orthanc::GlobalProperty_GetLastChangeIndex) || 182 Orthanc::GlobalProperty_GetLastChangeIndex) ||
182 property != 1) 183 property != 1)
183 { 184 {
184 needToRunUpgradeV1toV2 = true; 185 needToRunUpgradeV1toV2 = true;
245 } 246 }
246 247
247 248
248 uint64_t PostgreSQLIndex::GetTotalCompressedSize(DatabaseManager& manager) 249 uint64_t PostgreSQLIndex::GetTotalCompressedSize(DatabaseManager& manager)
249 { 250 {
250 // Fast version if extension "./FastTotalSize.sql" is installed
251 uint64_t result; 251 uint64_t result;
252 252
253 { 253 {
254 DatabaseManager::CachedStatement statement( 254 DatabaseManager::CachedStatement statement(
255 STATEMENT_FROM_HERE, manager, 255 STATEMENT_FROM_HERE, manager,
273 } 273 }
274 274
275 275
276 uint64_t PostgreSQLIndex::GetTotalUncompressedSize(DatabaseManager& manager) 276 uint64_t PostgreSQLIndex::GetTotalUncompressedSize(DatabaseManager& manager)
277 { 277 {
278 // Fast version if extension "./FastTotalSize.sql" is installed
279 uint64_t result; 278 uint64_t result;
280 279
281 { 280 {
282 DatabaseManager::CachedStatement statement( 281 DatabaseManager::CachedStatement statement(
283 STATEMENT_FROM_HERE, manager, 282 STATEMENT_FROM_HERE, manager,
284 "SELECT * FROM ComputeStatisticsReadOnly(1)"); 283 "SELECT * FROM ComputeStatisticsReadOnly(1)");
285 284
286 statement.Execute(); 285 statement.Execute();
287 286
288 result = static_cast<uint64_t>(statement.ReadInteger64(0)); 287 if (statement.IsNull(0))
288 {
289 return 0;
290 }
291 else
292 {
293 result = static_cast<uint64_t>(statement.ReadInteger64(0));
294 }
289 } 295 }
290 296
291 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added 297 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added
292 // assert(result == IndexBackend::GetTotalUncompressedSize(manager)); 298 // assert(result == IndexBackend::GetTotalUncompressedSize(manager));
293 return result; 299 return result;
651 657
652 658
653 uint64_t PostgreSQLIndex::GetResourcesCount(DatabaseManager& manager, 659 uint64_t PostgreSQLIndex::GetResourcesCount(DatabaseManager& manager,
654 OrthancPluginResourceType resourceType) 660 OrthancPluginResourceType resourceType)
655 { 661 {
656 // Optimized version thanks to the "FastCountResources.sql" extension
657
658 assert(OrthancPluginResourceType_Patient == 0 && 662 assert(OrthancPluginResourceType_Patient == 0 &&
659 OrthancPluginResourceType_Study == 1 && 663 OrthancPluginResourceType_Study == 1 &&
660 OrthancPluginResourceType_Series == 2 && 664 OrthancPluginResourceType_Series == 2 &&
661 OrthancPluginResourceType_Instance == 3); 665 OrthancPluginResourceType_Instance == 3);
662 666
667 manager, 671 manager,
668 std::string("SELECT * FROM ComputeStatisticsReadOnly(") + boost::lexical_cast<std::string>(resourceType + 2) + ")"); // For an explanation of the "+ 2" below, check out "PrepareIndex.sql" 672 std::string("SELECT * FROM ComputeStatisticsReadOnly(") + boost::lexical_cast<std::string>(resourceType + 2) + ")"); // For an explanation of the "+ 2" below, check out "PrepareIndex.sql"
669 673
670 statement.Execute(); 674 statement.Execute();
671 675
672 result = static_cast<uint64_t>(statement.ReadInteger64(0)); 676 if (statement.IsNull(0))
677 {
678 return 0;
679 }
680 else
681 {
682 result = static_cast<uint64_t>(statement.ReadInteger64(0));
683 }
673 } 684 }
674 685
675 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added 686 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added
676 assert(result == IndexBackend::GetResourcesCount(manager, resourceType)); 687 // assert(result == IndexBackend::GetResourcesCount(manager, resourceType));
677 688
678 return result; 689 return result;
679 } 690 }
680 691
681 692