| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- // Turn version history off everywhere except workflows.
- //
- // Only two places in the codebase read a version: the workflow controller (the
- // editor's version picker, publish and restore) and the runner (loading the
- // published version to run it). Both are about workflows. Everywhere else the
- // history is written on every save and read by nothing - and maxVersions 0
- // means unlimited, so it never stops growing.
- //
- // executions is the worst of it: 481 MB, and each run writes its record two or
- // three times - before the walk, on a pause, at the end - so every one of those
- // is kept for ever.
- //
- // Disabling stops new versions being recorded. History already written stays
- // readable, so this is reversible and reclaims nothing by itself.
- #include <smartbotic/database/client.hpp>
- #include <cstdio>
- #include <string>
- #include <vector>
- using namespace smartbotic::database;
- int main() {
- Client::Config cfg; cfg.address="192.168.2.150:9004"; cfg.project="smartbotic-automation";
- Client c(cfg);
- if (!c.connect()) return 1;
- const std::vector<std::string> keep = {"workflows"};
- std::vector<std::string> names;
- for (auto& n : c.listCollections()) {
- auto bare = n.rfind(':')==std::string::npos ? n : n.substr(n.rfind(':')+1);
- names.push_back(bare);
- }
- int off=0, kept=0, skipped=0;
- for (auto& n : names) {
- auto current = c.getCollectionConfig(n);
- bool on = current.versioningEnabled.value_or(true);
- bool must_keep = false;
- for (auto& k : keep) if (n == k) must_keep = true;
- if (must_keep) { printf(" %-28s left ON (its history is read)\n", n.c_str()); kept++; continue; }
- if (!on) { skipped++; continue; }
- Client::CollectionConfig want;
- // timestampPrecision has to be cleared explicitly. The struct defaults it
- // to "ms", and only an EMPTY string leaves the collection's setting
- // alone - so constructing this and setting one field silently rewrites
- // the other. It did: sixteen collections went from ns to ms, and every
- // document written afterwards carried milliseconds in a field where the
- // older ones carry nanoseconds, which makes any numeric sort or range
- // over _created_at and _updated_at wrong.
- want.timestampPrecision = "";
- want.versioningEnabled = false;
- if (c.configureCollection(n, want)) { printf(" %-28s versioning off\n", n.c_str()); off++; }
- else printf(" %-28s FAILED\n", n.c_str());
- }
- printf("turned off %d, left on %d, already off %d\n", off, kept, skipped);
- return 0;
- }
|