Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerIndex.cpp @ 4558:2f4d7ec9b993 db-changes
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Mar 2021 16:58:35 +0100 |
parents | b6d4b735eb4d |
children | 19b1921aee06 |
comparison
equal
deleted
inserted
replaced
4557:b6d4b735eb4d | 4558:2f4d7ec9b993 |
---|---|
1042 | 1042 |
1043 return StoreStatus_Failure; | 1043 return StoreStatus_Failure; |
1044 } | 1044 } |
1045 | 1045 |
1046 | 1046 |
1047 void ServerIndex::GetGlobalStatistics(/* out */ uint64_t& diskSize, | |
1048 /* out */ uint64_t& uncompressedSize, | |
1049 /* out */ uint64_t& countPatients, | |
1050 /* out */ uint64_t& countStudies, | |
1051 /* out */ uint64_t& countSeries, | |
1052 /* out */ uint64_t& countInstances) | |
1053 { | |
1054 boost::mutex::scoped_lock lock(mutex_); | |
1055 diskSize = db_.GetTotalCompressedSize(); | |
1056 uncompressedSize = db_.GetTotalUncompressedSize(); | |
1057 countPatients = db_.GetResourceCount(ResourceType_Patient); | |
1058 countStudies = db_.GetResourceCount(ResourceType_Study); | |
1059 countSeries = db_.GetResourceCount(ResourceType_Series); | |
1060 countInstances = db_.GetResourceCount(ResourceType_Instance); | |
1061 } | |
1062 | |
1063 | |
1064 SeriesStatus ServerIndex::GetSeriesStatus(IDatabaseWrapper& db, | 1047 SeriesStatus ServerIndex::GetSeriesStatus(IDatabaseWrapper& db, |
1065 int64_t id, | 1048 int64_t id, |
1066 int64_t expectedNumberOfInstances) | 1049 int64_t expectedNumberOfInstances) |
1067 { | 1050 { |
1068 std::list<std::string> values; | 1051 std::list<std::string> values; |
1175 | 1158 |
1176 target["Last"] = static_cast<int>(last); | 1159 target["Last"] = static_cast<int>(last); |
1177 } | 1160 } |
1178 | 1161 |
1179 | 1162 |
1180 void ServerIndex::GetChanges(Json::Value& target, | |
1181 int64_t since, | |
1182 unsigned int maxResults) | |
1183 { | |
1184 std::list<ServerIndexChange> changes; | |
1185 bool done; | |
1186 bool hasLast = false; | |
1187 int64_t last = 0; | |
1188 | |
1189 { | |
1190 boost::mutex::scoped_lock lock(mutex_); | |
1191 | |
1192 // Fix wrt. Orthanc <= 1.3.2: A transaction was missing, as | |
1193 // "GetLastChange()" involves calls to "GetPublicId()" | |
1194 Transaction transaction(*this); | |
1195 | |
1196 db_.GetChanges(changes, done, since, maxResults); | |
1197 if (changes.empty()) | |
1198 { | |
1199 last = db_.GetLastChangeIndex(); | |
1200 hasLast = true; | |
1201 } | |
1202 | |
1203 transaction.Commit(0); | |
1204 } | |
1205 | |
1206 FormatLog(target, changes, "Changes", done, since, hasLast, last); | |
1207 } | |
1208 | |
1209 | |
1210 void ServerIndex::GetLastChange(Json::Value& target) | |
1211 { | |
1212 std::list<ServerIndexChange> changes; | |
1213 bool hasLast = false; | |
1214 int64_t last = 0; | |
1215 | |
1216 { | |
1217 boost::mutex::scoped_lock lock(mutex_); | |
1218 | |
1219 // Fix wrt. Orthanc <= 1.3.2: A transaction was missing, as | |
1220 // "GetLastChange()" involves calls to "GetPublicId()" | |
1221 Transaction transaction(*this); | |
1222 | |
1223 db_.GetLastChange(changes); | |
1224 if (changes.empty()) | |
1225 { | |
1226 last = db_.GetLastChangeIndex(); | |
1227 hasLast = true; | |
1228 } | |
1229 | |
1230 transaction.Commit(0); | |
1231 } | |
1232 | |
1233 FormatLog(target, changes, "Changes", true, 0, hasLast, last); | |
1234 } | |
1235 | |
1236 | |
1237 void ServerIndex::LogExportedResource(const std::string& publicId, | 1163 void ServerIndex::LogExportedResource(const std::string& publicId, |
1238 const std::string& remoteModality) | 1164 const std::string& remoteModality) |
1239 { | 1165 { |
1240 boost::mutex::scoped_lock lock(mutex_); | 1166 boost::mutex::scoped_lock lock(mutex_); |
1241 Transaction transaction(*this); | 1167 Transaction transaction(*this); |
1323 db_.LogExportedResource(resource); | 1249 db_.LogExportedResource(resource); |
1324 transaction.Commit(0); | 1250 transaction.Commit(0); |
1325 } | 1251 } |
1326 | 1252 |
1327 | 1253 |
1328 void ServerIndex::GetExportedResources(Json::Value& target, | |
1329 int64_t since, | |
1330 unsigned int maxResults) | |
1331 { | |
1332 std::list<ExportedResource> exported; | |
1333 bool done; | |
1334 | |
1335 { | |
1336 boost::mutex::scoped_lock lock(mutex_); | |
1337 db_.GetExportedResources(exported, done, since, maxResults); | |
1338 } | |
1339 | |
1340 FormatLog(target, exported, "Exports", done, since, false, -1); | |
1341 } | |
1342 | |
1343 | |
1344 void ServerIndex::GetLastExportedResource(Json::Value& target) | |
1345 { | |
1346 std::list<ExportedResource> exported; | |
1347 | |
1348 { | |
1349 boost::mutex::scoped_lock lock(mutex_); | |
1350 db_.GetLastExportedResource(exported); | |
1351 } | |
1352 | |
1353 FormatLog(target, exported, "Exports", true, 0, false, -1); | |
1354 } | |
1355 | |
1356 | |
1357 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize) | 1254 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize) |
1358 { | 1255 { |
1359 if (maximumStorageSize_ != 0) | 1256 if (maximumStorageSize_ != 0) |
1360 { | 1257 { |
1361 assert(maximumStorageSize_ >= instanceSize); | 1258 assert(maximumStorageSize_ >= instanceSize); |
2519 const Tuple tuple(t1, t2, t3, t4); | 2416 const Tuple tuple(t1, t2, t3, t4); |
2520 TupleOperationsWrapper<ReadOnlyOperationsT4, Tuple> wrapper(*this, tuple); | 2417 TupleOperationsWrapper<ReadOnlyOperationsT4, Tuple> wrapper(*this, tuple); |
2521 index.Apply(wrapper); | 2418 index.Apply(wrapper); |
2522 } | 2419 } |
2523 }; | 2420 }; |
2421 | |
2422 | |
2423 template <typename T1, | |
2424 typename T2, | |
2425 typename T3, | |
2426 typename T4, | |
2427 typename T5> | |
2428 class ReadOnlyOperationsT5 : public boost::noncopyable | |
2429 { | |
2430 public: | |
2431 typedef typename boost::tuple<T1, T2, T3, T4, T5> Tuple; | |
2432 | |
2433 virtual ~ReadOnlyOperationsT5() | |
2434 { | |
2435 } | |
2436 | |
2437 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, | |
2438 const Tuple& tuple) = 0; | |
2439 | |
2440 void Apply(ServerIndex& index, | |
2441 T1 t1, | |
2442 T2 t2, | |
2443 T3 t3, | |
2444 T4 t4, | |
2445 T5 t5) | |
2446 { | |
2447 const Tuple tuple(t1, t2, t3, t4, t5); | |
2448 TupleOperationsWrapper<ReadOnlyOperationsT5, Tuple> wrapper(*this, tuple); | |
2449 index.Apply(wrapper); | |
2450 } | |
2451 }; | |
2452 | |
2453 | |
2454 template <typename T1, | |
2455 typename T2, | |
2456 typename T3, | |
2457 typename T4, | |
2458 typename T5, | |
2459 typename T6> | |
2460 class ReadOnlyOperationsT6 : public boost::noncopyable | |
2461 { | |
2462 public: | |
2463 typedef typename boost::tuple<T1, T2, T3, T4, T5, T6> Tuple; | |
2464 | |
2465 virtual ~ReadOnlyOperationsT6() | |
2466 { | |
2467 } | |
2468 | |
2469 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, | |
2470 const Tuple& tuple) = 0; | |
2471 | |
2472 void Apply(ServerIndex& index, | |
2473 T1 t1, | |
2474 T2 t2, | |
2475 T3 t3, | |
2476 T4 t4, | |
2477 T5 t5, | |
2478 T6 t6) | |
2479 { | |
2480 const Tuple tuple(t1, t2, t3, t4, t5, t6); | |
2481 TupleOperationsWrapper<ReadOnlyOperationsT6, Tuple> wrapper(*this, tuple); | |
2482 index.Apply(wrapper); | |
2483 } | |
2484 }; | |
2524 } | 2485 } |
2525 | 2486 |
2526 | 2487 |
2527 class ServerIndex::ReadOnlyWrapper : public IReadOnlyOperations | 2488 class ServerIndex::ReadOnlyWrapper : public IReadOnlyOperations |
2528 { | 2489 { |
2577 { | 2538 { |
2578 try | 2539 try |
2579 { | 2540 { |
2580 boost::mutex::scoped_lock lock(mutex_); // TODO - REMOVE | 2541 boost::mutex::scoped_lock lock(mutex_); // TODO - REMOVE |
2581 | 2542 |
2543 Transaction transaction(*this); // TODO - Only if "TransactionType_SingleStatement" | |
2544 | |
2582 if (readOperations != NULL) | 2545 if (readOperations != NULL) |
2583 { | 2546 { |
2584 ReadOnlyTransaction transaction(db_); | 2547 ReadOnlyTransaction transaction(db_); |
2585 readOperations->Apply(transaction); | 2548 readOperations->Apply(transaction); |
2586 } | 2549 } |
2588 { | 2551 { |
2589 assert(writeOperations != NULL); | 2552 assert(writeOperations != NULL); |
2590 ReadWriteTransaction transaction(db_); | 2553 ReadWriteTransaction transaction(db_); |
2591 writeOperations->Apply(transaction); | 2554 writeOperations->Apply(transaction); |
2592 } | 2555 } |
2556 | |
2557 transaction.Commit(0); | |
2593 | 2558 |
2594 return; // Success | 2559 return; // Success |
2595 } | 2560 } |
2596 catch (OrthancException& e) | 2561 catch (OrthancException& e) |
2597 { | 2562 { |
2934 operations.Apply(*this, &attachment, instancePublicId, contentType); | 2899 operations.Apply(*this, &attachment, instancePublicId, contentType); |
2935 return operations.HasFound(); | 2900 return operations.HasFound(); |
2936 } | 2901 } |
2937 | 2902 |
2938 | 2903 |
2939 | |
2940 void ServerIndex::GetAllUuids(std::list<std::string>& target, | 2904 void ServerIndex::GetAllUuids(std::list<std::string>& target, |
2941 ResourceType resourceType) | 2905 ResourceType resourceType) |
2942 { | 2906 { |
2943 class Operations : public ReadOnlyOperationsT2<std::list<std::string>*, ResourceType> | 2907 class Operations : public ReadOnlyOperationsT2<std::list<std::string>*, ResourceType> |
2944 { | 2908 { |
2945 public: | 2909 public: |
2946 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2910 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2947 const Tuple& tuple) ORTHANC_OVERRIDE | 2911 const Tuple& tuple) ORTHANC_OVERRIDE |
2948 { | 2912 { |
2913 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | |
2949 transaction.GetAllPublicIds(*tuple.get<0>(), tuple.get<1>()); | 2914 transaction.GetAllPublicIds(*tuple.get<0>(), tuple.get<1>()); |
2950 } | 2915 } |
2951 }; | 2916 }; |
2952 | 2917 |
2953 Operations operations; | 2918 Operations operations; |
2954 operations.Apply(*this, &target, resourceType); | 2919 operations.Apply(*this, &target, resourceType); |
2955 } | 2920 } |
2956 | |
2957 | 2921 |
2958 | 2922 |
2959 void ServerIndex::GetAllUuids(std::list<std::string>& target, | 2923 void ServerIndex::GetAllUuids(std::list<std::string>& target, |
2960 ResourceType resourceType, | 2924 ResourceType resourceType, |
2961 size_t since, | 2925 size_t since, |
2971 { | 2935 { |
2972 public: | 2936 public: |
2973 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2937 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2974 const Tuple& tuple) ORTHANC_OVERRIDE | 2938 const Tuple& tuple) ORTHANC_OVERRIDE |
2975 { | 2939 { |
2940 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | |
2976 transaction.GetAllPublicIds(*tuple.get<0>(), tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); | 2941 transaction.GetAllPublicIds(*tuple.get<0>(), tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); |
2977 } | 2942 } |
2978 }; | 2943 }; |
2979 | 2944 |
2980 Operations operations; | 2945 Operations operations; |
2981 operations.Apply(*this, &target, resourceType, since, limit); | 2946 operations.Apply(*this, &target, resourceType, since, limit); |
2982 } | 2947 } |
2983 } | 2948 } |
2949 | |
2950 | |
2951 void ServerIndex::GetGlobalStatistics(/* out */ uint64_t& diskSize, | |
2952 /* out */ uint64_t& uncompressedSize, | |
2953 /* out */ uint64_t& countPatients, | |
2954 /* out */ uint64_t& countStudies, | |
2955 /* out */ uint64_t& countSeries, | |
2956 /* out */ uint64_t& countInstances) | |
2957 { | |
2958 class Operations : public ReadOnlyOperationsT6<uint64_t*, uint64_t*, uint64_t*, uint64_t*, uint64_t*, uint64_t*> | |
2959 { | |
2960 public: | |
2961 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
2962 const Tuple& tuple) ORTHANC_OVERRIDE | |
2963 { | |
2964 *tuple.get<0>() = transaction.GetTotalCompressedSize(); | |
2965 *tuple.get<1>() = transaction.GetTotalUncompressedSize(); | |
2966 *tuple.get<2>() = transaction.GetResourceCount(ResourceType_Patient); | |
2967 *tuple.get<3>() = transaction.GetResourceCount(ResourceType_Study); | |
2968 *tuple.get<4>() = transaction.GetResourceCount(ResourceType_Series); | |
2969 *tuple.get<5>() = transaction.GetResourceCount(ResourceType_Instance); | |
2970 } | |
2971 }; | |
2972 | |
2973 Operations operations; | |
2974 operations.Apply(*this, &diskSize, &uncompressedSize, &countPatients, | |
2975 &countStudies, &countSeries, &countInstances); | |
2976 } | |
2977 | |
2978 | |
2979 void ServerIndex::GetChanges(Json::Value& target, | |
2980 int64_t since, | |
2981 unsigned int maxResults) | |
2982 { | |
2983 class Operations : public ReadOnlyOperationsT3<Json::Value*, int64_t, unsigned int> | |
2984 { | |
2985 public: | |
2986 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
2987 const Tuple& tuple) ORTHANC_OVERRIDE | |
2988 { | |
2989 // NB: In Orthanc <= 1.3.2, a transaction was missing, as | |
2990 // "GetLastChange()" involves calls to "GetPublicId()" | |
2991 | |
2992 std::list<ServerIndexChange> changes; | |
2993 bool done; | |
2994 bool hasLast = false; | |
2995 int64_t last = 0; | |
2996 | |
2997 transaction.GetChanges(changes, done, tuple.get<1>(), tuple.get<2>()); | |
2998 if (changes.empty()) | |
2999 { | |
3000 last = transaction.GetLastChangeIndex(); | |
3001 hasLast = true; | |
3002 } | |
3003 | |
3004 FormatLog(*tuple.get<0>(), changes, "Changes", done, tuple.get<1>(), hasLast, last); | |
3005 } | |
3006 }; | |
3007 | |
3008 Operations operations; | |
3009 operations.Apply(*this, &target, since, maxResults); | |
3010 } | |
3011 | |
3012 | |
3013 void ServerIndex::GetLastChange(Json::Value& target) | |
3014 { | |
3015 class Operations : public ReadOnlyOperationsT1<Json::Value*> | |
3016 { | |
3017 public: | |
3018 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3019 const Tuple& tuple) ORTHANC_OVERRIDE | |
3020 { | |
3021 // NB: In Orthanc <= 1.3.2, a transaction was missing, as | |
3022 // "GetLastChange()" involves calls to "GetPublicId()" | |
3023 | |
3024 std::list<ServerIndexChange> changes; | |
3025 bool hasLast = false; | |
3026 int64_t last = 0; | |
3027 | |
3028 transaction.GetLastChange(changes); | |
3029 if (changes.empty()) | |
3030 { | |
3031 last = transaction.GetLastChangeIndex(); | |
3032 hasLast = true; | |
3033 } | |
3034 | |
3035 FormatLog(*tuple.get<0>(), changes, "Changes", true, 0, hasLast, last); | |
3036 } | |
3037 }; | |
3038 | |
3039 Operations operations; | |
3040 operations.Apply(*this, &target); | |
3041 } | |
3042 | |
3043 | |
3044 void ServerIndex::GetExportedResources(Json::Value& target, | |
3045 int64_t since, | |
3046 unsigned int maxResults) | |
3047 { | |
3048 class Operations : public ReadOnlyOperationsT3<Json::Value*, int64_t, unsigned int> | |
3049 { | |
3050 public: | |
3051 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3052 const Tuple& tuple) ORTHANC_OVERRIDE | |
3053 { | |
3054 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | |
3055 | |
3056 std::list<ExportedResource> exported; | |
3057 bool done; | |
3058 transaction.GetExportedResources(exported, done, tuple.get<1>(), tuple.get<2>()); | |
3059 FormatLog(*tuple.get<0>(), exported, "Exports", done, tuple.get<1>(), false, -1); | |
3060 } | |
3061 }; | |
3062 | |
3063 Operations operations; | |
3064 operations.Apply(*this, &target, since, maxResults); | |
3065 } | |
3066 | |
3067 | |
3068 void ServerIndex::GetLastExportedResource(Json::Value& target) | |
3069 { | |
3070 class Operations : public ReadOnlyOperationsT1<Json::Value*> | |
3071 { | |
3072 public: | |
3073 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3074 const Tuple& tuple) ORTHANC_OVERRIDE | |
3075 { | |
3076 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | |
3077 | |
3078 std::list<ExportedResource> exported; | |
3079 transaction.GetLastExportedResource(exported); | |
3080 FormatLog(*tuple.get<0>(), exported, "Exports", true, 0, false, -1); | |
3081 } | |
3082 }; | |
3083 | |
3084 Operations operations; | |
3085 operations.Apply(*this, &target); | |
3086 } | |
2984 } | 3087 } |