Files
strfry/src/apps/dbutils/cmd_scan.cpp
Doug Hoyte 206b14a473 sync optimisations, DBQuery no longer loads eventPayload
- It is now up to the caller to do so
- QueryScheduler now can optionally not bother to ensure that the events are fresh
2023-07-29 01:14:38 -04:00

50 lines
1.1 KiB
C++

#include <iostream>
#include <docopt.h>
#include "golpe.h"
#include "DBQuery.h"
#include "events.h"
static const char USAGE[] =
R"(
Usage:
scan [--pause=<pause>] [--metrics] [--count] <filter>
)";
void cmd_scan(const std::vector<std::string> &subArgs) {
std::map<std::string, docopt::value> args = docopt::docopt(USAGE, subArgs, true, "");
uint64_t pause = 0;
if (args["--pause"]) pause = args["--pause"].asLong();
bool metrics = args["--metrics"].asBool();
bool count = args["--count"].asBool();
std::string filterStr = args["<filter>"].asString();
DBQuery query(tao::json::from_string(filterStr));
Decompressor decomp;
auto txn = env.txn_ro();
uint64_t numEvents = 0;
exitOnSigPipe();
while (1) {
bool complete = query.process(txn, [&](const auto &sub, uint64_t levId){
if (count) numEvents++;
else std::cout << getEventJson(txn, decomp, levId) << "\n";
}, pause ? pause : MAX_U64, metrics);
if (complete) break;
}
if (count) std::cout << numEvents << std::endl;
}