comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 72:8dd29af7c844 db-changes

new extension: FastTotalSize
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Jan 2019 14:43:35 +0100
parents d40c5fecd160
children aa81c1c80c75
comparison
equal deleted inserted replaced
71:d40c5fecd160 72:8dd29af7c844
185 185
186 t.Commit(); 186 t.Commit();
187 } 187 }
188 } 188 }
189 189
190 {
191 PostgreSQLTransaction t(*db);
192
193 int hasFastTotalSize = 0;
194 if (!LookupGlobalIntegerProperty(hasFastTotalSize, *db, t,
195 Orthanc::GlobalProperty_GetTotalSizeIsFast) ||
196 hasFastTotalSize != 1)
197 {
198 LOG(INFO) << "Installing the FastTotalSize extension";
199
200 std::string query;
201 Orthanc::EmbeddedResources::GetFileResource
202 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_TOTAL_SIZE);
203 db->Execute(query);
204
205 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1);
206
207 t.Commit();
208 }
209 }
210
190 return db.release(); 211 return db.release();
191 } 212 }
192 213
193 214
194 PostgreSQLIndex::PostgreSQLIndex(const PostgreSQLParameters& parameters) : 215 PostgreSQLIndex::PostgreSQLIndex(const PostgreSQLParameters& parameters) :
215 args.SetIntegerValue("type", static_cast<int>(type)); 236 args.SetIntegerValue("type", static_cast<int>(type));
216 237
217 statement.Execute(args); 238 statement.Execute(args);
218 239
219 return ReadInteger64(statement, 0); 240 return ReadInteger64(statement, 0);
241 }
242
243
244 uint64_t PostgreSQLIndex::GetTotalCompressedSize()
245 {
246 // Fast version if extension "./FastTotalSize.sql" is installed
247 DatabaseManager::CachedStatement statement(
248 STATEMENT_FROM_HERE, GetManager(),
249 "SELECT value FROM GlobalIntegers WHERE key = 0");
250
251 statement.SetReadOnly(true);
252 statement.Execute();
253
254 return static_cast<uint64_t>(ReadInteger64(statement, 0));
255 }
256
257
258 uint64_t PostgreSQLIndex::GetTotalUncompressedSize()
259 {
260 // Fast version if extension "./FastTotalSize.sql" is installed
261 DatabaseManager::CachedStatement statement(
262 STATEMENT_FROM_HERE, GetManager(),
263 "SELECT value FROM GlobalIntegers WHERE key = 1");
264
265 statement.SetReadOnly(true);
266 statement.Execute();
267
268 return static_cast<uint64_t>(ReadInteger64(statement, 0));
220 } 269 }
221 270
222 271
223 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, 272 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result,
224 const char* hashPatient, 273 const char* hashPatient,