Better deduplicating saved animations and recent/featured stickers.
GitOrigin-RevId: 2bc58b3fabbf1cb01727e584036846e6acde0cc6
This commit is contained in:
parent
71aa152460
commit
c8cfee8d7b
@ -664,7 +664,13 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise<Un
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!saved_animation_ids_.empty() && saved_animation_ids_[0] == animation_id) {
|
||||
auto is_equal = [animation_id](FileId file_id) {
|
||||
return file_id == animation_id ||
|
||||
(file_id.get_remote() == animation_id.get_remote() && animation_id.get_remote() != 0);
|
||||
};
|
||||
|
||||
if (!saved_animation_ids_.empty() && is_equal(saved_animation_ids_[0])) {
|
||||
// fast path
|
||||
if (saved_animation_ids_[0].get_remote() == 0 && animation_id.get_remote() != 0) {
|
||||
saved_animation_ids_[0] = animation_id;
|
||||
save_saved_animations_to_database();
|
||||
@ -697,7 +703,7 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise<Un
|
||||
return false;
|
||||
}
|
||||
|
||||
auto it = std::find(saved_animation_ids_.begin(), saved_animation_ids_.end(), animation_id);
|
||||
auto it = std::find_if(saved_animation_ids_.begin(), saved_animation_ids_.end(), is_equal);
|
||||
if (it == saved_animation_ids_.end()) {
|
||||
if (static_cast<int32>(saved_animation_ids_.size()) == saved_animations_limit_) {
|
||||
saved_animation_ids_.back() = animation_id;
|
||||
@ -707,7 +713,7 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise<Un
|
||||
it = saved_animation_ids_.end() - 1;
|
||||
}
|
||||
std::rotate(saved_animation_ids_.begin(), it, it + 1);
|
||||
CHECK(saved_animation_ids_[0] == animation_id);
|
||||
CHECK(is_equal(saved_animation_ids_[0]));
|
||||
if (saved_animation_ids_[0].get_remote() == 0 && animation_id.get_remote() != 0) {
|
||||
saved_animation_ids_[0] = animation_id;
|
||||
}
|
||||
|
@ -3916,8 +3916,12 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i
|
||||
return false;
|
||||
}
|
||||
|
||||
auto is_equal = [sticker_id](FileId file_id) {
|
||||
return file_id == sticker_id || (file_id.get_remote() == sticker_id.get_remote() && sticker_id.get_remote() != 0);
|
||||
};
|
||||
|
||||
vector<FileId> &sticker_ids = recent_sticker_ids_[is_attached];
|
||||
if (!sticker_ids.empty() && sticker_ids[0] == sticker_id) {
|
||||
if (!sticker_ids.empty() && is_equal(sticker_ids[0])) {
|
||||
if (sticker_ids[0].get_remote() == 0 && sticker_id.get_remote() != 0) {
|
||||
sticker_ids[0] = sticker_id;
|
||||
save_recent_stickers_to_database(is_attached);
|
||||
@ -3953,7 +3957,7 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i
|
||||
|
||||
need_update_recent_stickers_[is_attached] = true;
|
||||
|
||||
auto it = std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id);
|
||||
auto it = std::find_if(sticker_ids.begin(), sticker_ids.end(), is_equal);
|
||||
if (it == sticker_ids.end()) {
|
||||
if (static_cast<int32>(sticker_ids.size()) == recent_stickers_limit_) {
|
||||
sticker_ids.back() = sticker_id;
|
||||
@ -4311,7 +4315,11 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise<Unit>
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!favorite_sticker_ids_.empty() && favorite_sticker_ids_[0] == sticker_id) {
|
||||
auto is_equal = [sticker_id](FileId file_id) {
|
||||
return file_id == sticker_id || (file_id.get_remote() == sticker_id.get_remote() && sticker_id.get_remote() != 0);
|
||||
};
|
||||
|
||||
if (!favorite_sticker_ids_.empty() && is_equal(favorite_sticker_ids_[0])) {
|
||||
if (favorite_sticker_ids_[0].get_remote() == 0 && sticker_id.get_remote() != 0) {
|
||||
favorite_sticker_ids_[0] = sticker_id;
|
||||
save_favorite_stickers_to_database();
|
||||
@ -4345,7 +4353,7 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise<Unit>
|
||||
return false;
|
||||
}
|
||||
|
||||
auto it = std::find(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), sticker_id);
|
||||
auto it = std::find_if(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), is_equal);
|
||||
if (it == favorite_sticker_ids_.end()) {
|
||||
if (static_cast<int32>(favorite_sticker_ids_.size()) == favorite_stickers_limit_) {
|
||||
favorite_sticker_ids_.back() = sticker_id;
|
||||
|
@ -1264,8 +1264,8 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
|
||||
if (x_node->remote_.full && y_node->remote_.full && !x_node->remote_.full.value().is_web() &&
|
||||
!y_node->remote_.full.value().is_web() && y_node->remote_.is_full_alive &&
|
||||
x_node->remote_.full.value().get_dc_id() != y_node->remote_.full.value().get_dc_id()) {
|
||||
LOG(ERROR) << "File remote location was changed from " << y_node->remote_.full.value() << " to "
|
||||
<< x_node->remote_.full.value();
|
||||
LOG(WARNING) << "File remote location was changed from " << y_node->remote_.full.value() << " to "
|
||||
<< x_node->remote_.full.value();
|
||||
}
|
||||
|
||||
FileNodePtr nodes[] = {x_node, y_node, x_node};
|
||||
@ -2599,7 +2599,16 @@ Result<FileId> FileManager::check_input_file_id(FileType type, Result<FileId> re
|
||||
// But it will not be duped if has_input_media(), so for now we can't return main_file_id
|
||||
return dup_file_id(file_id);
|
||||
}
|
||||
return FileId(file_node->main_file_id_.get(), file_id.get_remote());
|
||||
|
||||
int32 remote_id = file_id.get_remote();
|
||||
if (remote_id == 0) {
|
||||
RemoteInfo info{file_view.remote_location(), FileLocationSource::FromUser, file_id};
|
||||
remote_id = remote_location_info_.add(info);
|
||||
if (remote_location_info_.get(remote_id).file_id_ == file_id) {
|
||||
get_file_id_info(file_id)->pin_flag_ = true;
|
||||
}
|
||||
}
|
||||
return FileId(file_node->main_file_id_.get(), remote_id);
|
||||
}
|
||||
|
||||
Result<FileId> FileManager::get_input_thumbnail_file_id(const tl_object_ptr<td_api::InputFile> &thumbnail_input_file,
|
||||
|
Reference in New Issue
Block a user