Mercurial > hg > orthanc
comparison OrthancServer/DatabaseWrapper.cpp @ 1158:badc14fee61f db-changes
speed up db
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 16 Sep 2014 18:01:42 +0200 |
parents | 649d47854314 |
children | 1ea4094d077c |
comparison
equal
deleted
inserted
replaced
1157:22ef457b7985 | 1158:badc14fee61f |
---|---|
90 | 90 |
91 listener_.SignalFileDeleted(info); | 91 listener_.SignalFileDeleted(info); |
92 } | 92 } |
93 }; | 93 }; |
94 | 94 |
95 class SignalResourceDeleted : public SQLite::IScalarFunction | |
96 { | |
97 private: | |
98 IServerIndexListener& listener_; | |
99 | |
100 public: | |
101 SignalResourceDeleted(IServerIndexListener& listener) : | |
102 listener_(listener) | |
103 { | |
104 } | |
105 | |
106 virtual const char* GetName() const | |
107 { | |
108 return "SignalResourceDeleted"; | |
109 } | |
110 | |
111 virtual unsigned int GetCardinality() const | |
112 { | |
113 return 2; | |
114 } | |
115 | |
116 virtual void Compute(SQLite::FunctionContext& context) | |
117 { | |
118 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1)); | |
119 listener_.SignalResourceDeleted(type, context.GetStringValue(0)); | |
120 } | |
121 }; | |
122 | |
95 class SignalRemainingAncestor : public SQLite::IScalarFunction | 123 class SignalRemainingAncestor : public SQLite::IScalarFunction |
96 { | 124 { |
97 private: | 125 private: |
98 bool hasRemainingAncestor_; | 126 bool hasRemainingAncestor_; |
99 std::string remainingPublicId_; | 127 std::string remainingPublicId_; |
850 unsigned int v = boost::lexical_cast<unsigned int>(version); | 878 unsigned int v = boost::lexical_cast<unsigned int>(version); |
851 | 879 |
852 /** | 880 /** |
853 * History of the database versions: | 881 * History of the database versions: |
854 * - Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive) | 882 * - Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive) |
855 * - Version 4: from Orthanc 0.7.3 (inclusive) | 883 * - Version 4: from Orthanc 0.7.3 to Orthanc 0.8.3 (inclusive) |
884 * - Version 5: from Orthanc 0.8.4 (inclusive) | |
856 **/ | 885 **/ |
857 | 886 |
858 // This version of Orthanc is only compatible with versions 3 of 4 of the DB schema | 887 // This version of Orthanc is only compatible with versions 3, 4 and 5 of the DB schema |
859 ok = (v == 3 || v == 4); | 888 ok = (v == 3 || v == 4 || v == 5); |
860 | 889 |
861 if (v == 3) | 890 if (v == 3) |
862 { | 891 { |
863 LOG(WARNING) << "Upgrading database version from 3 to 4"; | 892 LOG(WARNING) << "Upgrading database version from 3 to 4"; |
864 std::string upgrade; | 893 std::string upgrade; |
865 EmbeddedResources::GetFileResource(upgrade, EmbeddedResources::UPGRADE_DATABASE_3_TO_4); | 894 EmbeddedResources::GetFileResource(upgrade, EmbeddedResources::UPGRADE_DATABASE_3_TO_4); |
866 db_.BeginTransaction(); | 895 db_.BeginTransaction(); |
867 db_.Execute(upgrade); | 896 db_.Execute(upgrade); |
868 db_.CommitTransaction(); | 897 db_.CommitTransaction(); |
898 v = 4; | |
899 } | |
900 | |
901 if (v == 4) | |
902 { | |
903 LOG(WARNING) << "Upgrading database version from 4 to 5"; | |
904 std::string upgrade; | |
905 EmbeddedResources::GetFileResource(upgrade, EmbeddedResources::UPGRADE_DATABASE_4_TO_5); | |
906 db_.BeginTransaction(); | |
907 db_.Execute(upgrade); | |
908 db_.CommitTransaction(); | |
909 v = 5; | |
869 } | 910 } |
870 } | 911 } |
871 catch (boost::bad_lexical_cast&) | 912 catch (boost::bad_lexical_cast&) |
872 { | 913 { |
873 } | 914 } |
879 } | 920 } |
880 | 921 |
881 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; | 922 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; |
882 db_.Register(signalRemainingAncestor_); | 923 db_.Register(signalRemainingAncestor_); |
883 db_.Register(new Internals::SignalFileDeleted(listener_)); | 924 db_.Register(new Internals::SignalFileDeleted(listener_)); |
925 db_.Register(new Internals::SignalResourceDeleted(listener_)); | |
884 } | 926 } |
885 | 927 |
886 uint64_t DatabaseWrapper::GetResourceCount(ResourceType resourceType) | 928 uint64_t DatabaseWrapper::GetResourceCount(ResourceType resourceType) |
887 { | 929 { |
888 SQLite::Statement s(db_, SQLITE_FROM_HERE, | 930 SQLite::Statement s(db_, SQLITE_FROM_HERE, |