changeset 524:48aba35fe64e large-queries

merged BEGIN and SET TRANSACTION statements
author Alain Mazy <am@orthanc.team>
date Tue, 09 Jul 2024 16:30:52 +0200
parents 9413451fd984
children 25cfcb752af6
files Framework/PostgreSQL/PostgreSQLTransaction.cpp PostgreSQL/NEWS
diffstat 2 files changed, 8 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/PostgreSQL/PostgreSQLTransaction.cpp	Tue Jul 09 16:21:25 2024 +0200
+++ b/Framework/PostgreSQL/PostgreSQLTransaction.cpp	Tue Jul 09 16:30:52 2024 +0200
@@ -65,37 +65,28 @@
       LOG(ERROR) << "PostgreSQL: Beginning a transaction twice!";
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
-
-    database_.ExecuteMultiLines("BEGIN");
+    std::string transactionStatement;  // if not defined, will use the default DB transaction isolation level
 
     switch (type)
     {
       case TransactionType_ReadWrite:
       {
-        std::string statement = database_.GetReadWriteTransactionStatement();
-        if (!statement.empty()) // if not defined, will use the default DB transaction isolation level
-        {
-          database_.ExecuteMultiLines(statement);
-        }
-
+        transactionStatement = database_.GetReadWriteTransactionStatement();
         break;
       }
 
       case TransactionType_ReadOnly:
       {
-        std::string statement = database_.GetReadOnlyTransactionStatement();
-        if (!statement.empty()) // if not defined, will use the default DB transaction isolation level
-        {
-          database_.ExecuteMultiLines(statement);
-        }
-
+        transactionStatement = database_.GetReadOnlyTransactionStatement();
         break;
       }
 
       default:
         throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
-        
+
+    database_.ExecuteMultiLines("BEGIN; " + transactionStatement);
+
     isOpen_ = true;
   }
 
--- a/PostgreSQL/NEWS	Tue Jul 09 16:21:25 2024 +0200
+++ b/PostgreSQL/NEWS	Tue Jul 09 16:30:52 2024 +0200
@@ -12,8 +12,9 @@
   - using more prepared SQL statements:
     - InsertOrUpdateMetadata
     - ExecuteSetResourcesContentTags
+  - merged BEGIN and SET TRANSACTION statements
   - reduced the number of round-trips between Orthanc and the PostgreSQL server:
-    - e.g: when receiving an instance in an existing series, reduced the number of SQL queries from 13 to 10 (to be continued)
+    - e.g: when receiving an instance in an existing series, reduced the number of SQL queries from 13 to 9 (to be continued)
 
 
 Release 6.2 (2024-03-25)