Implemented get_archived_theos in AnalyticsServiceServer

This commit is contained in:
taha afzal committed 2022-02-28 19:29:55 -05:00
1 parent 0cef0ce4e5
commit f9449f5fa6
1 file changed
+22 -3
@@ -350,16 +350,35 @@ void AnalyticsServiceServer::delete_report(
void AnalyticsServiceServer::archive_theos(
const bts::api::analytics::ArchivedTheoList &theo_list,
const api::Response<::bts::api::ResultMessage> &) {
const api::Response<::bts::api::ResultMessage> &resp) {
const std::string &ns = me->archived_theos_ns;
const std::string key = std::to_string(theo_list.save_time());
std::string value = utils::pb::to_string(theo_list);
me->theos_store->insert(ns, key, value);
api::ResultMessage res;
res.set_success(true);
resp(res);
}
void AnalyticsServiceServer::get_archived_theos(
const bts::api::analytics::ArchivedTheoRetrieval &,
const bts::api::Response<bts::api::analytics::ArchivedTheoList> &) {}
const bts::api::analytics::ArchivedTheoRetrieval &ret,
const bts::api::Response<bts::api::analytics::ArchivedTheoList> &resp) {
ArchivedTheoList rv = {};
const auto &rows = me->theos_store->retrieve_all();
uint64_t max_diff = std::numeric_limits<uint64_t>::max();
for (const auto &ns : rows) {
for (const auto &kv : ns.second) {
uint64_t ts = std::stoull(kv.first);
int diff = ts - ret.save_time();
uint64_t abs_diff = std::abs(diff);
if (abs_diff < max_diff) {
max_diff = abs_diff;
utils::pb::from_string(kv.second, &rv);
}
}
}
resp(rv);
}
AnalyticsServiceServer::~AnalyticsServiceServer() {}