Asynchronously reload emoji keywords languages after restart.

GitOrigin-RevId: 1f24d44c715d96aead91402fdc7f6d7abf04d041
This commit is contained in:
levlam 2020-01-08 19:25:36 +03:00
parent 3659757dc3
commit dcb15d0a13
2 changed files with 11 additions and 4 deletions

View File

@ -4948,8 +4948,8 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
}
auto language_codes = result.move_as_ok();
LOG(INFO) << "Receive language codes " << language_codes << " for emojis search";
td::remove_if(language_codes, [](const auto &language_code) {
LOG(INFO) << "Receive language codes " << language_codes << " for emojis search with key " << key;
td::remove_if(language_codes, [](const string &language_code) {
if (language_code.empty() || language_code.find('$') != string::npos) {
LOG(ERROR) << "Receive language_code \"" << language_code << '"';
return true;
@ -4963,10 +4963,13 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
std::sort(language_codes.begin(), language_codes.end());
language_codes.erase(std::unique(language_codes.begin(), language_codes.end()), language_codes.end());
G()->td_db()->get_sqlite_pmc()->set(key, implode(language_codes, '$'), Auto());
auto it = emoji_language_codes_.find(key);
CHECK(it != emoji_language_codes_.end());
if (it->second != language_codes) {
LOG(INFO) << "Update emoji language codes for " << key << " to " << language_codes;
G()->td_db()->get_sqlite_pmc()->set(key, implode(language_codes, '$'), Auto());
it->second = std::move(language_codes);
}
for (auto &promise : promises) {
promise.set_value(Unit());
@ -5007,6 +5010,9 @@ vector<string> StickersManager::get_emoji_language_codes(const string &input_lan
load_emoji_keywords_difference(language_code);
}
}
if (reloaded_emoji_keywords_.insert(key).second) {
load_language_codes(std::move(language_codes), std::move(key), Auto());
}
}
return it->second;
}

View File

@ -613,6 +613,7 @@ class StickersManager : public Actor {
std::unordered_map<string, vector<string>> emoji_language_codes_;
std::unordered_map<string, int32> emoji_language_code_versions_;
std::unordered_map<string, double> emoji_language_code_last_difference_times_;
std::unordered_set<string> reloaded_emoji_keywords_;
std::unordered_map<string, vector<Promise<Unit>>> load_emoji_keywords_queries_;
std::unordered_map<string, vector<Promise<Unit>>> load_language_codes_queries_;
std::unordered_map<int64, string> emoji_suggestions_urls_;