Don't resave loaded active stories to database if they didn't change.
This commit is contained in:
parent
956e31810a
commit
7624311ac6
@ -1252,7 +1252,7 @@ StoryManager::ActiveStories *StoryManager::on_get_active_stories_from_database(D
|
|||||||
}
|
}
|
||||||
|
|
||||||
on_update_active_stories(owner_dialog_id, saved_active_stories.max_read_story_id_, std::move(story_ids),
|
on_update_active_stories(owner_dialog_id, saved_active_stories.max_read_story_id_, std::move(story_ids),
|
||||||
Promise<Unit>());
|
Promise<Unit>(), true);
|
||||||
|
|
||||||
return get_active_stories_editable(owner_dialog_id);
|
return get_active_stories_editable(owner_dialog_id);
|
||||||
}
|
}
|
||||||
@ -2682,17 +2682,19 @@ DialogId StoryManager::on_get_user_stories(DialogId owner_dialog_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id,
|
void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id,
|
||||||
vector<StoryId> &&story_ids, Promise<Unit> &&promise) {
|
vector<StoryId> &&story_ids, Promise<Unit> &&promise, bool from_database) {
|
||||||
td::remove_if(story_ids, [&](StoryId story_id) {
|
if (td::remove_if(story_ids, [&](StoryId story_id) {
|
||||||
if (!story_id.is_server()) {
|
if (!story_id.is_server()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!is_active_story(get_story({owner_dialog_id, story_id}))) {
|
if (!is_active_story(get_story({owner_dialog_id, story_id}))) {
|
||||||
LOG(INFO) << "Receive expired " << story_id << " in " << owner_dialog_id;
|
LOG(INFO) << "Receive expired " << story_id << " in " << owner_dialog_id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
})) {
|
||||||
|
from_database = false;
|
||||||
|
}
|
||||||
if (story_ids.empty() || max_read_story_id.get() < story_ids[0].get()) {
|
if (story_ids.empty() || max_read_story_id.get() < story_ids[0].get()) {
|
||||||
max_read_story_id = StoryId();
|
max_read_story_id = StoryId();
|
||||||
}
|
}
|
||||||
@ -2712,7 +2714,9 @@ void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId ma
|
|||||||
update_story_list_sent_total_count(active_stories->story_list_id_);
|
update_story_list_sent_total_count(active_stories->story_list_id_);
|
||||||
}
|
}
|
||||||
active_stories_.erase(owner_dialog_id);
|
active_stories_.erase(owner_dialog_id);
|
||||||
save_active_stories(owner_dialog_id, nullptr, std::move(promise));
|
if (!from_database) {
|
||||||
|
save_active_stories(owner_dialog_id, nullptr, std::move(promise));
|
||||||
|
}
|
||||||
send_update_chat_active_stories(owner_dialog_id, nullptr);
|
send_update_chat_active_stories(owner_dialog_id, nullptr);
|
||||||
} else {
|
} else {
|
||||||
max_read_story_ids_.erase(owner_dialog_id);
|
max_read_story_ids_.erase(owner_dialog_id);
|
||||||
@ -2753,7 +2757,7 @@ void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId ma
|
|||||||
} else if (update_active_stories_order(owner_dialog_id, active_stories.get(), &need_save_to_database)) {
|
} else if (update_active_stories_order(owner_dialog_id, active_stories.get(), &need_save_to_database)) {
|
||||||
send_update_chat_active_stories(owner_dialog_id, active_stories.get());
|
send_update_chat_active_stories(owner_dialog_id, active_stories.get());
|
||||||
}
|
}
|
||||||
if (need_save_to_database) {
|
if (need_save_to_database && !from_database) {
|
||||||
save_active_stories(owner_dialog_id, active_stories.get(), std::move(promise));
|
save_active_stories(owner_dialog_id, active_stories.get(), std::move(promise));
|
||||||
} else {
|
} else {
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
|
@ -440,7 +440,7 @@ class StoryManager final : public Actor {
|
|||||||
void on_toggle_story_is_pinned(StoryId story_id, bool is_pinned, Promise<Unit> &&promise);
|
void on_toggle_story_is_pinned(StoryId story_id, bool is_pinned, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id, vector<StoryId> &&story_ids,
|
void on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id, vector<StoryId> &&story_ids,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise, bool from_database = false);
|
||||||
|
|
||||||
bool update_active_stories_order(DialogId owner_dialog_id, ActiveStories *active_stories,
|
bool update_active_stories_order(DialogId owner_dialog_id, ActiveStories *active_stories,
|
||||||
bool *need_save_to_database);
|
bool *need_save_to_database);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user