disable-versioning.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Turn version history off everywhere except workflows.
  2. //
  3. // Only two places in the codebase read a version: the workflow controller (the
  4. // editor's version picker, publish and restore) and the runner (loading the
  5. // published version to run it). Both are about workflows. Everywhere else the
  6. // history is written on every save and read by nothing - and maxVersions 0
  7. // means unlimited, so it never stops growing.
  8. //
  9. // executions is the worst of it: 481 MB, and each run writes its record two or
  10. // three times - before the walk, on a pause, at the end - so every one of those
  11. // is kept for ever.
  12. //
  13. // Disabling stops new versions being recorded. History already written stays
  14. // readable, so this is reversible and reclaims nothing by itself.
  15. #include <smartbotic/database/client.hpp>
  16. #include <cstdio>
  17. #include <string>
  18. #include <vector>
  19. using namespace smartbotic::database;
  20. int main() {
  21. Client::Config cfg; cfg.address="192.168.2.150:9004"; cfg.project="smartbotic-automation";
  22. Client c(cfg);
  23. if (!c.connect()) return 1;
  24. const std::vector<std::string> keep = {"workflows"};
  25. std::vector<std::string> names;
  26. for (auto& n : c.listCollections()) {
  27. auto bare = n.rfind(':')==std::string::npos ? n : n.substr(n.rfind(':')+1);
  28. names.push_back(bare);
  29. }
  30. int off=0, kept=0, skipped=0;
  31. for (auto& n : names) {
  32. auto current = c.getCollectionConfig(n);
  33. bool on = current.versioningEnabled.value_or(true);
  34. bool must_keep = false;
  35. for (auto& k : keep) if (n == k) must_keep = true;
  36. if (must_keep) { printf(" %-28s left ON (its history is read)\n", n.c_str()); kept++; continue; }
  37. if (!on) { skipped++; continue; }
  38. Client::CollectionConfig want; // precision left unset, so untouched
  39. want.versioningEnabled = false;
  40. if (c.configureCollection(n, want)) { printf(" %-28s versioning off\n", n.c_str()); off++; }
  41. else printf(" %-28s FAILED\n", n.c_str());
  42. }
  43. printf("turned off %d, left on %d, already off %d\n", off, kept, skipped);
  44. return 0;
  45. }