Remove story viewer cache.

This commit is contained in:
levlam 2023-08-07 16:24:31 +03:00
parent eb74e6eb2a
commit 511a9da2b2
4 changed files with 0 additions and 70 deletions

View File

@ -1209,7 +1209,6 @@ void StoryManager::on_story_can_get_viewers_timeout(int64 story_global_id) {
// can_get_viewers flag has changed
send_update_story(story_full_id, story);
}
cached_story_viewers_.erase(story_full_id);
}
void StoryManager::load_expired_database_stories() {
@ -2344,18 +2343,6 @@ void StoryManager::get_story_viewers(StoryId story_id, const td_api::storyViewer
}
StoryViewer offset_viewer{UserId(offset_user_id), offset_date};
auto &cached_viewers = cached_story_viewers_[story_full_id];
if (cached_viewers != nullptr && story->content_ != nullptr &&
(cached_viewers->total_count_ == story->interaction_info_.get_view_count() || !offset_viewer.is_empty())) {
auto result = cached_viewers->viewers_.get_sublist(offset_viewer, limit);
if (!result.is_empty()) {
// can return the viewers
// don't need to reget the viewers, because story->interaction_info_.get_view_count() is updated every 10 seconds
td_->contacts_manager_->on_view_user_active_stories(result.get_user_ids());
return promise.set_value(result.get_story_viewers_object(td_->contacts_manager_.get()));
}
}
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), story_id, offset_viewer, promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> result) mutable {
@ -2401,16 +2388,6 @@ void StoryManager::on_get_story_viewers(
}
on_story_changed(story_full_id, story, true, true);
}
auto &cached_viewers = cached_story_viewers_[story_full_id];
if (cached_viewers == nullptr) {
cached_viewers = make_unique<CachedStoryViewers>();
}
if (total_count < cached_viewers->total_count_) {
LOG(ERROR) << "Total viewer count decreased from " << cached_viewers->total_count_ << " to " << total_count;
} else {
cached_viewers->total_count_ = total_count;
}
cached_viewers->viewers_.add_sublist(offset, story_viewers);
}
td_->contacts_manager_->on_view_user_active_stories(story_viewers.get_user_ids());
@ -2945,7 +2922,6 @@ void StoryManager::on_delete_story(StoryFullId story_full_id) {
being_edited_stories_.erase(edited_stories_it);
}
edit_generations_.erase(story_full_id);
cached_story_viewers_.erase(story_full_id);
auto active_stories = get_active_stories_force(owner_dialog_id, "on_get_deleted_story");
if (active_stories != nullptr && contains(active_stories->story_ids_, story_id)) {

View File

@ -157,11 +157,6 @@ class StoryManager final : public Actor {
void parse(ParserT &parser);
};
struct CachedStoryViewers {
int32 total_count_ = -1;
StoryViewers viewers_;
};
struct StoryList {
int32 server_total_count_ = -1;
int32 sent_total_count_ = -1;
@ -571,8 +566,6 @@ class StoryManager final : public Actor {
FlatHashMap<StoryFullId, uint32, StoryFullIdHash> opened_stories_;
FlatHashMap<StoryFullId, unique_ptr<CachedStoryViewers>, StoryFullIdHash> cached_story_viewers_;
FlatHashMap<StoryFullId, vector<Promise<Unit>>, StoryFullIdHash> reload_story_queries_;
FlatHashMap<FileId, unique_ptr<PendingStory>, FileIdHash> being_uploaded_files_;

View File

@ -41,41 +41,6 @@ StoryViewers::StoryViewers(vector<telegram_api::object_ptr<telegram_api::storyVi
}
}
StoryViewers StoryViewers::get_sublist(const StoryViewer &offset, int32 limit) const {
StoryViewers result;
bool found = offset.is_empty();
for (auto &story_viewer : story_viewers_) {
if (found) {
if (limit-- <= 0) {
break;
}
result.story_viewers_.push_back(story_viewer);
} else if (story_viewer == offset) {
found = true;
}
}
return result;
}
void StoryViewers::add_sublist(const StoryViewer &offset, const StoryViewers &sublist) {
if (offset.is_empty()) {
if (story_viewers_.empty()) {
story_viewers_ = sublist.story_viewers_;
} else {
auto old_viewers = std::move(story_viewers_);
for (auto &viewer : sublist.story_viewers_) {
if (viewer == old_viewers[0]) {
append(story_viewers_, old_viewers);
return;
}
story_viewers_.push_back(viewer);
}
}
} else if (!story_viewers_.empty() && story_viewers_.back() == offset) {
append(story_viewers_, sublist.story_viewers_);
}
}
vector<UserId> StoryViewers::get_user_ids() const {
return transform(story_viewers_, [](auto &viewer) { return viewer.get_user_id(); });
}

View File

@ -60,10 +60,6 @@ class StoryViewers {
return story_viewers_.empty();
}
StoryViewers get_sublist(const StoryViewer &offset, int32 limit) const;
void add_sublist(const StoryViewer &offset, const StoryViewers &sublist);
vector<UserId> get_user_ids() const;
td_api::object_ptr<td_api::storyViewers> get_story_viewers_object(ContactsManager *contacts_manager) const;