comparison OrthancServer/SQLiteDatabaseWrapper.cpp @ 3018:e3b5c07146a3 db-changes

speeding up the computation of the size of the attachments in SQLite
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Dec 2018 16:04:17 +0100
parents 517fc4767ae0
children 8336204d95dc
comparison
equal deleted inserted replaced
3017:517fc4767ae0 3018:e3b5c07146a3
368 { 368 {
369 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion, 369 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion,
370 "Incompatible version of the Orthanc database: " + tmp); 370 "Incompatible version of the Orthanc database: " + tmp);
371 } 371 }
372 372
373 // New in Orthanc 1.5.1
374 if (version_ == 6)
375 {
376 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseTracksSizeOfAttachments) ||
377 tmp != "1")
378 {
379 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments";
380 std::string query;
381 EmbeddedResources::GetFileResource(query, EmbeddedResources::INSTALL_TRACK_ATTACHMENTS_SIZE);
382 db_.Execute(query);
383 }
384 }
385
373 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; 386 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
374 db_.Register(signalRemainingAncestor_); 387 db_.Register(signalRemainingAncestor_);
375 } 388 }
376 389
377 390
888 } 901 }
889 902
890 903
891 uint64_t SQLiteDatabaseWrapper::GetTotalCompressedSize() 904 uint64_t SQLiteDatabaseWrapper::GetTotalCompressedSize()
892 { 905 {
893 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(compressedSize) FROM AttachedFiles"); 906 // Old SQL query that was used in Orthanc <= 1.5.0:
907 // SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(compressedSize) FROM AttachedFiles");
908
909 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT value FROM GlobalIntegers WHERE key=0");
894 s.Run(); 910 s.Run();
895 return static_cast<uint64_t>(s.ColumnInt64(0)); 911 return static_cast<uint64_t>(s.ColumnInt64(0));
896 } 912 }
897 913
898 914
899 uint64_t SQLiteDatabaseWrapper::GetTotalUncompressedSize() 915 uint64_t SQLiteDatabaseWrapper::GetTotalUncompressedSize()
900 { 916 {
901 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(uncompressedSize) FROM AttachedFiles"); 917 // Old SQL query that was used in Orthanc <= 1.5.0:
918 // SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(uncompressedSize) FROM AttachedFiles");
919
920 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT value FROM GlobalIntegers WHERE key=1");
902 s.Run(); 921 s.Run();
903 return static_cast<uint64_t>(s.ColumnInt64(0)); 922 return static_cast<uint64_t>(s.ColumnInt64(0));
904 } 923 }
905 924
906 925