AnalyticsServiceServer's archive vol request now respects the symbol in the arguments
This commit is contained in:
1 parent
cd576793f7
commit
e8dfbe1d01
2 files changed
+29
-8
No files matched your search
@@ -363,20 +363,41 @@ void AnalyticsServiceServer::archive_theos(
|
||||
void AnalyticsServiceServer::get_archived_theos(
|
||||
const bts::api::analytics::ArchivedTheoRetrieval &ret,
|
||||
const bts::api::Response<bts::api::analytics::ArchivedTheoList> &resp) {
|
||||
auto contains_st = [&](const ArchivedTheoList &tl) {
|
||||
for (const auto &st : tl.sec_tups()) {
|
||||
// TODO: compare all, just not symbol
|
||||
if (st.symbol() == ret.sec_tup().symbol()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
ArchivedTheoList rv = {};
|
||||
const auto &rows = me->theos_store->retrieve_all();
|
||||
uint64_t max_diff = std::numeric_limits<uint64_t>::max();
|
||||
std::string key = "";
|
||||
// this is rather slow, we can speed up by sorting the keys
|
||||
// and searching based on distance from ret.save_time()
|
||||
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);
|
||||
ArchivedTheoList tl;
|
||||
utils::pb::from_string(kv.second, &tl);
|
||||
if (contains_st(tl)) {
|
||||
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) {
|
||||
key = kv.first;
|
||||
max_diff = abs_diff;
|
||||
rv = tl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG(Gen, Info,
|
||||
"AnalyticsServiceServer::get_archived_theo save_time: {} symbol: {} "
|
||||
"key: {}",
|
||||
ret.save_time(), ret.sec_tup().symbol(), key);
|
||||
resp(rv);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user