Skip to content

Commit

Permalink
Delete inline query message content one hour after result cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Dec 13, 2024
1 parent d961806 commit 53acb2b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 27 additions & 2 deletions td/telegram/InlineQueriesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ class SendWebViewResultMessageQuery final : public Td::ResultHandler {
InlineQueriesManager::InlineQueriesManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
drop_inline_query_result_timeout_.set_callback(on_drop_inline_query_result_timeout_callback);
drop_inline_query_result_timeout_.set_callback_data(static_cast<void *>(this));

drop_inline_query_message_timeout_.set_callback(on_drop_inline_query_message_timeout_callback);
drop_inline_query_message_timeout_.set_callback_data(static_cast<void *>(this));

next_inline_query_time_ = Time::now();
}

Expand Down Expand Up @@ -393,13 +397,34 @@ void InlineQueriesManager::on_drop_inline_query_result_timeout(int64 query_hash)
if (it->second.pending_request_count == 0) {
if (it->second.results != nullptr) {
auto query_id = it->second.results->inline_query_id_;
inline_message_contents_.erase(query_id);
query_id_to_bot_user_id_.erase(query_id);
if (query_id) {
drop_inline_query_message_timeout_.set_timeout_in(query_id, 3600);
}
}
inline_query_results_.erase(it);
}
}

void InlineQueriesManager::on_drop_inline_query_message_timeout_callback(void *inline_queries_manager_ptr,
int64 query_id) {
if (G()->close_flag()) {
return;
}

auto inline_queries_manager = static_cast<InlineQueriesManager *>(inline_queries_manager_ptr);
send_closure_later(inline_queries_manager->actor_id(inline_queries_manager),
&InlineQueriesManager::on_drop_inline_query_message_timeout, query_id);
}

void InlineQueriesManager::on_drop_inline_query_message_timeout(int64 query_id) {
if (G()->close_flag()) {
return;
}

inline_message_contents_.erase(query_id);
query_id_to_bot_user_id_.erase(query_id);
}

void InlineQueriesManager::after_get_difference() {
if (td_->auth_manager_->is_bot()) {
return;
Expand Down
5 changes: 5 additions & 0 deletions td/telegram/InlineQueriesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class InlineQueriesManager final : public Actor {

void on_drop_inline_query_result_timeout(int64 query_hash);

static void on_drop_inline_query_message_timeout_callback(void *inline_queries_manager_ptr, int64 query_id);

void on_drop_inline_query_message_timeout(int64 query_id);

void loop() final;

void tear_down() final;
Expand Down Expand Up @@ -173,6 +177,7 @@ class InlineQueriesManager final : public Actor {
};

MultiTimeout drop_inline_query_result_timeout_{"DropInlineQueryResultTimeout"};
MultiTimeout drop_inline_query_message_timeout_{"DropInlineQueryMessageTimeout"};
FlatHashMap<uint64, InlineQueryResult> inline_query_results_; // query_hash -> result

FlatHashMap<int64, FlatHashMap<string, InlineMessageContent>>
Expand Down

0 comments on commit 53acb2b

Please sign in to comment.