comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 523:9413451fd984 large-queries

ExecuteSetResourcesContentTags is now using a cached prepared statement
author Alain Mazy <am@orthanc.team>
date Tue, 09 Jul 2024 16:21:25 +0200
parents c49136b34891
children 25cfcb752af6
comparison
equal deleted inserted replaced
522:c49136b34891 523:9413451fd984
485 485
486 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 486 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
487 static void ExecuteSetResourcesContentTags( 487 static void ExecuteSetResourcesContentTags(
488 DatabaseManager& manager, 488 DatabaseManager& manager,
489 const std::string& table, 489 const std::string& table,
490 const std::string& variablePrefix,
491 uint32_t count, 490 uint32_t count,
492 const OrthancPluginResourcesContentTags* tags) 491 const OrthancPluginResourcesContentTags* tags)
493 { 492 {
494 std::string sql; 493 std::string sql;
494
495 std::vector<std::string> resourceIds;
496 std::vector<std::string> groups;
497 std::vector<std::string> elements;
498 std::vector<std::string> values;
499
495 Dictionary args; 500 Dictionary args;
496 501
497 for (uint32_t i = 0; i < count; i++) 502 for (uint32_t i = 0; i < count; i++)
498 { 503 {
499 std::string name = variablePrefix + boost::lexical_cast<std::string>(i); 504 std::string resourceArgName = "r" + boost::lexical_cast<std::string>(i);
500 505 std::string groupArgName = "g" + boost::lexical_cast<std::string>(i);
501 args.SetUtf8Value(name, tags[i].value); 506 std::string elementArgName = "e" + boost::lexical_cast<std::string>(i);
502 507 std::string valueArgName = "v" + boost::lexical_cast<std::string>(i);
503 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " + 508
504 boost::lexical_cast<std::string>(tags[i].group) + ", " + 509 args.SetIntegerValue(resourceArgName, tags[i].resource);
505 boost::lexical_cast<std::string>(tags[i].element) + ", " + 510 args.SetInteger32Value(elementArgName, tags[i].element);
506 "${" + name + "})"); 511 args.SetInteger32Value(groupArgName, tags[i].group);
512 args.SetUtf8Value(valueArgName, tags[i].value);
513
514 std::string insert = ("(${" + resourceArgName + "}, ${" +
515 groupArgName + "}, ${" +
516 elementArgName + "}, " +
517 "${" + valueArgName + "})");
507 518
508 if (sql.empty()) 519 if (sql.empty())
509 { 520 {
510 sql = "INSERT INTO " + table + " VALUES " + insert; 521 sql = "INSERT INTO " + table + " VALUES " + insert;
511 } 522 }
515 } 526 }
516 } 527 }
517 528
518 if (!sql.empty()) 529 if (!sql.empty())
519 { 530 {
520 DatabaseManager::StandaloneStatement statement(manager, sql); 531 DatabaseManager::CachedStatement statement(STATEMENT_FROM_HERE_DYNAMIC(sql), manager, sql);
521 532
522 for (uint32_t i = 0; i < count; i++) 533 for (uint32_t i = 0; i < count; i++)
523 { 534 {
524 statement.SetParameterType(variablePrefix + boost::lexical_cast<std::string>(i), 535 statement.SetParameterType("r" + boost::lexical_cast<std::string>(i),
536 ValueType_Integer64);
537 statement.SetParameterType("g" + boost::lexical_cast<std::string>(i),
538 ValueType_Integer32);
539 statement.SetParameterType("e" + boost::lexical_cast<std::string>(i),
540 ValueType_Integer32);
541 statement.SetParameterType("v" + boost::lexical_cast<std::string>(i),
525 ValueType_Utf8String); 542 ValueType_Utf8String);
526 } 543 }
527 544
528 statement.Execute(args); 545 statement.Execute(args);
529 } 546 }
605 uint32_t countMainDicomTags, 622 uint32_t countMainDicomTags,
606 const OrthancPluginResourcesContentTags* mainDicomTags, 623 const OrthancPluginResourcesContentTags* mainDicomTags,
607 uint32_t countMetadata, 624 uint32_t countMetadata,
608 const OrthancPluginResourcesContentMetadata* metadata) 625 const OrthancPluginResourcesContentMetadata* metadata)
609 { 626 {
610 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", "i", 627 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", countIdentifierTags, identifierTags);
611 countIdentifierTags, identifierTags); 628
612 629 ExecuteSetResourcesContentTags(manager, "MainDicomTags", countMainDicomTags, mainDicomTags);
613 ExecuteSetResourcesContentTags(manager, "MainDicomTags", "t",
614 countMainDicomTags, mainDicomTags);
615 630
616 ExecuteSetResourcesContentMetadata(manager, HasRevisionsSupport(), countMetadata, metadata); 631 ExecuteSetResourcesContentMetadata(manager, HasRevisionsSupport(), countMetadata, metadata);
617 632
618 } 633 }
619 634