Do not store empty promises in QueryCombiner.

GitOrigin-RevId: 5222075d6722008902b0337d2aee369aee0f005c
This commit is contained in:
levlam 2019-02-25 19:27:06 +03:00
parent 40ae8b9fd5
commit a2a864852d
2 changed files with 8 additions and 4 deletions

View File

@ -10,12 +10,15 @@ namespace td {
void QueryCombiner::add_query(int64 query_id, Promise<Promise<Unit>> &&send_query, Promise<Unit> &&promise) {
auto &query = queries_[query_id];
query.promises.push_back(std::move(promise));
if (query.promises.size() != 1) {
// query has already been sent, just wait for the result
if (promise) {
query.promises.push_back(std::move(promise));
}
if (query.is_sent) {
// just wait for the result
return;
}
query.is_sent = true;
send_query.set_value(PromiseCreator::lambda([actor_id = actor_id(this), query_id](Result<Unit> &&result) {
send_closure(actor_id, &QueryCombiner::on_get_query_result, query_id, std::move(result));
}));
@ -24,7 +27,7 @@ void QueryCombiner::add_query(int64 query_id, Promise<Promise<Unit>> &&send_quer
void QueryCombiner::on_get_query_result(int64 query_id, Result<Unit> &&result) {
auto it = queries_.find(query_id);
CHECK(it != queries_.end());
CHECK(!it->second.promises.empty());
CHECK(it->second.is_sent);
auto promises = std::move(it->second.promises);
queries_.erase(it);

View File

@ -28,6 +28,7 @@ class QueryCombiner : public Actor {
private:
struct QueryInfo {
vector<Promise<Unit>> promises;
bool is_sent = false;
};
std::unordered_map<int64, QueryInfo> queries_;