comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 572:6667bd31beaf find-refactoring

ReadOnly mode continued
author Alain Mazy <am@orthanc.team>
date Thu, 26 Sep 2024 17:24:29 +0200
parents d8ee2f676a3c
children 523241efee57
comparison
equal deleted inserted replaced
568:77c8544bbd7d 572:6667bd31beaf
41 // Some aliases for internal properties 41 // Some aliases for internal properties
42 static const GlobalProperty GlobalProperty_HasTrigramIndex = GlobalProperty_DatabaseInternal0; 42 static const GlobalProperty GlobalProperty_HasTrigramIndex = GlobalProperty_DatabaseInternal0;
43 static const GlobalProperty GlobalProperty_HasCreateInstance = GlobalProperty_DatabaseInternal1; 43 static const GlobalProperty GlobalProperty_HasCreateInstance = GlobalProperty_DatabaseInternal1;
44 static const GlobalProperty GlobalProperty_HasFastCountResources = GlobalProperty_DatabaseInternal2; 44 static const GlobalProperty GlobalProperty_HasFastCountResources = GlobalProperty_DatabaseInternal2;
45 static const GlobalProperty GlobalProperty_GetLastChangeIndex = GlobalProperty_DatabaseInternal3; 45 static const GlobalProperty GlobalProperty_GetLastChangeIndex = GlobalProperty_DatabaseInternal3;
46 static const GlobalProperty GlobalProperty_HasComputeStatisticsReadOnly = GlobalProperty_DatabaseInternal4;
46 } 47 }
47 48
48 49
49 namespace OrthancDatabases 50 namespace OrthancDatabases
50 { 51 {
204 t.GetDatabaseTransaction().ExecuteMultiLines(query); 205 t.GetDatabaseTransaction().ExecuteMultiLines(query);
205 206
206 // apply all idempotent changes that are in the PrepareIndexV2 207 // apply all idempotent changes that are in the PrepareIndexV2
207 ApplyPrepareIndex(t, manager); 208 ApplyPrepareIndex(t, manager);
208 } 209 }
210
211 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER,
212 Orthanc::GlobalProperty_HasComputeStatisticsReadOnly) ||
213 property != 1)
214 {
215 // apply all idempotent changes that are in the PrepareIndex. In this case, we are just interested by
216 // ComputeStatisticsReadOnly() that does not need to be uninstalled in case of downgrade.
217 ApplyPrepareIndex(t, manager);
218 }
209 } 219 }
210 220
211 t.Commit(); 221 t.Commit();
212 } 222 }
213 } 223 }
241 uint64_t result; 251 uint64_t result;
242 252
243 { 253 {
244 DatabaseManager::CachedStatement statement( 254 DatabaseManager::CachedStatement statement(
245 STATEMENT_FROM_HERE, manager, 255 STATEMENT_FROM_HERE, manager,
246 "SELECT * FROM UpdateSingleStatistic(0)"); 256 "SELECT * FROM ComputeStatisticsReadOnly(0)");
247 257
248 statement.Execute(); 258 statement.Execute();
249 259
250 result = static_cast<uint64_t>(statement.ReadInteger64(0)); 260 result = static_cast<uint64_t>(statement.ReadInteger64(0));
251 } 261 }
262 uint64_t result; 272 uint64_t result;
263 273
264 { 274 {
265 DatabaseManager::CachedStatement statement( 275 DatabaseManager::CachedStatement statement(
266 STATEMENT_FROM_HERE, manager, 276 STATEMENT_FROM_HERE, manager,
267 "SELECT * FROM UpdateSingleStatistic(1)"); 277 "SELECT * FROM ComputeStatisticsReadOnly(1)");
268 278
269 statement.Execute(); 279 statement.Execute();
270 280
271 result = static_cast<uint64_t>(statement.ReadInteger64(0)); 281 result = static_cast<uint64_t>(statement.ReadInteger64(0));
272 } 282 }
646 uint64_t result; 656 uint64_t result;
647 657
648 { 658 {
649 DatabaseManager::StandaloneStatement statement( 659 DatabaseManager::StandaloneStatement statement(
650 manager, 660 manager,
651 std::string("SELECT * FROM UpdateSingleStatistic(") + boost::lexical_cast<std::string>(resourceType + 2) + ")"); // For an explanation of the "+ 2" below, check out "PrepareIndex.sql" 661 std::string("SELECT * FROM ComputeStatisticsReadOnly(") + boost::lexical_cast<std::string>(resourceType + 2) + ")"); // For an explanation of the "+ 2" below, check out "PrepareIndex.sql"
652 662
653 statement.Execute(); 663 statement.Execute();
654 664
655 result = static_cast<uint64_t>(statement.ReadInteger64(0)); 665 result = static_cast<uint64_t>(statement.ReadInteger64(0));
656 } 666 }