Optimize installed premium stickers traversal in getPremiumStickers.

This commit is contained in:
levlam 2022-08-07 20:35:13 +03:00
parent 36d7adef38
commit 5304ac7ccf
3 changed files with 9 additions and 6 deletions

View File

@ -3471,6 +3471,9 @@ StickerSetId StickersManager::on_get_messages_sticker_set(StickerSetId sticker_s
continue;
}
if (!is_bot && get_sticker(sticker_id.second)->is_premium_) {
s->premium_sticker_positions_.push_back(static_cast<int32>(s->sticker_ids_.size()));
}
s->sticker_ids_.push_back(sticker_id.second);
if (!is_bot) {
document_id_to_sticker_id.emplace(sticker_id.first, sticker_id.second);
@ -4256,12 +4259,8 @@ void StickersManager::do_get_premium_stickers(int32 limit, Promise<td_api::objec
continue;
}
for (auto sticker_id : sticker_set->sticker_ids_) {
const Sticker *s = get_sticker(sticker_id);
if (!s->is_premium_) {
continue;
}
sticker_ids.push_back(sticker_id);
for (auto premium_sticker_position : sticker_set->premium_sticker_positions_) {
sticker_ids.push_back(sticker_set->sticker_ids_[premium_sticker_position]);
if (sticker_ids.size() == limit_size_t) {
return promise.set_value(get_stickers_object(sticker_ids));
}

View File

@ -420,6 +420,7 @@ class StickersManager final : public Actor {
int64 thumbnail_document_id_ = 0;
vector<FileId> sticker_ids_;
vector<int32> premium_sticker_positions_;
FlatHashMap<string, vector<FileId>> emoji_stickers_map_; // emoji -> stickers
FlatHashMap<FileId, vector<string>, FileIdHash> sticker_emojis_map_; // sticker -> emojis

View File

@ -394,6 +394,9 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
LOG_IF(ERROR, sticker->set_id_.is_valid()) << "Sticker " << sticker_id << " set_id has changed";
sticker->set_id_ = sticker_set->id_;
}
if (sticker->is_premium_) {
sticker_set->premium_sticker_positions_.push_back(static_cast<int32>(sticker_set->sticker_ids_.size() - 1));
}
if (sticker_set->was_loaded_) {
vector<string> emojis;