comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 433:5964ce6385a5 pg-transactions

use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
author Alain Mazy <am@osimis.io>
date Wed, 13 Dec 2023 15:48:56 +0100
parents 8b7c1c423367
children 23c7af6f671a
comparison
equal deleted inserted replaced
432:8b7c1c423367 433:5964ce6385a5
463 return statement.ReadInteger64(0); 463 return statement.ReadInteger64(0);
464 } 464 }
465 } 465 }
466 } 466 }
467 467
468 void PostgreSQLIndex::ClearDeletedFiles(DatabaseManager& manager)
469 {
470 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS
471 DatabaseManager::CachedStatement statement(
472 STATEMENT_FROM_HERE, manager,
473 "CREATE TEMPORARY TABLE IF NOT EXISTS DeletedFiles("
474 "uuid VARCHAR(64) NOT NULL,"
475 "fileType INTEGER, "
476 "compressedSize BIGINT, "
477 "uncompressedSize BIGINT, "
478 "compressionType INTEGER, "
479 "uncompressedHash VARCHAR(40),"
480 "compressedHash VARCHAR(40)"
481 ");"
482 );
483 statement.Execute();
484 }
485 {
486 DatabaseManager::CachedStatement statement(
487 STATEMENT_FROM_HERE, manager,
488 "DELETE FROM DeletedFiles;"
489 );
490
491 statement.Execute();
492 }
493 }
494
495 void PostgreSQLIndex::ClearDeletedResources(DatabaseManager& manager)
496 {
497 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS
498 DatabaseManager::CachedStatement statement(
499 STATEMENT_FROM_HERE, manager,
500 "CREATE TEMPORARY TABLE IF NOT EXISTS DeletedResources("
501 "resourceType INTEGER NOT NULL,"
502 "publicId VARCHAR(64) NOT NULL"
503 ");"
504 );
505 statement.Execute();
506 }
507 {
508 DatabaseManager::CachedStatement statement(
509 STATEMENT_FROM_HERE, manager,
510 "DELETE FROM DeletedResources;"
511 );
512
513 statement.Execute();
514 }
515
516 }
517
518 void PostgreSQLIndex::ClearRemainingAncestor(DatabaseManager& manager)
519 {
520 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS
521 DatabaseManager::CachedStatement statement(
522 STATEMENT_FROM_HERE, manager,
523 "CREATE TEMPORARY TABLE IF NOT EXISTS RemainingAncestor("
524 "resourceType INTEGER NOT NULL,"
525 "publicId VARCHAR(64) NOT NULL"
526 ")"
527 );
528
529 statement.Execute();
530 }
531 {
532 DatabaseManager::CachedStatement statement(
533 STATEMENT_FROM_HERE, manager,
534 "DELETE FROM RemainingAncestor;"
535 );
536
537 statement.Execute();
538 }
539
540 }
541
542
468 543
469 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 544 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
470 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, 545 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result,
471 DatabaseManager& manager, 546 DatabaseManager& manager,
472 const char* hashPatient, 547 const char* hashPatient,