mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-24 03:35:52 +01:00
Fail flood-limited queries with a delay.
This commit is contained in:
parent
12c56318a8
commit
09c9db306a
@ -4195,18 +4195,15 @@ void Client::send(PromisedQueryPtr query) {
|
||||
auto update_per_minute = static_cast<int64>(stat->get_minute_update_count(td::Time::now()) * 60);
|
||||
if (stat->get_active_request_count() > 500 + update_per_minute) {
|
||||
LOG(INFO) << "Fail a query, because there are too many active queries: " << *query;
|
||||
flood_limited_query_count_++;
|
||||
return query->set_retry_after_error(60);
|
||||
return fail_query_flood_limit_exceeded(std::move(query));
|
||||
}
|
||||
if (stat->get_active_file_upload_bytes() > (static_cast<int64>(1) << 32) && !query->files().empty()) {
|
||||
LOG(INFO) << "Fail a query, because the total size of active file uploads is too big: " << *query;
|
||||
flood_limited_query_count_++;
|
||||
return query->set_retry_after_error(60);
|
||||
return fail_query_flood_limit_exceeded(std::move(query));
|
||||
}
|
||||
if (stat->get_active_file_upload_count() > 100 + update_per_minute / 5 && !query->files().empty()) {
|
||||
LOG(INFO) << "Fail a query, because there are too many active file uploads: " << *query;
|
||||
flood_limited_query_count_++;
|
||||
return query->set_retry_after_error(60);
|
||||
return fail_query_flood_limit_exceeded(std::move(query));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7580,8 +7577,7 @@ td::Status Client::process_send_message_query(PromisedQueryPtr &query) {
|
||||
// fast path
|
||||
auto it = yet_unsent_message_count_.find(r_chat_id.ok());
|
||||
if (it != yet_unsent_message_count_.end() && it->second >= MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) {
|
||||
flood_limited_query_count_++;
|
||||
query->set_retry_after_error(60);
|
||||
fail_query_flood_limit_exceeded(std::move(query));
|
||||
return Status::OK();
|
||||
}
|
||||
}
|
||||
@ -7889,8 +7885,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
|
||||
PromisedQueryPtr query) mutable {
|
||||
auto &count = yet_unsent_message_count_[chat_id];
|
||||
if (count >= MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) {
|
||||
flood_limited_query_count_++;
|
||||
return query->set_retry_after_error(60);
|
||||
return fail_query_flood_limit_exceeded(std::move(query));
|
||||
}
|
||||
auto message_count = input_message_contents.size();
|
||||
count += static_cast<int32>(message_count);
|
||||
@ -9527,8 +9522,7 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
|
||||
int64 reply_to_message_id, PromisedQueryPtr query) mutable {
|
||||
auto &count = yet_unsent_message_count_[chat_id];
|
||||
if (count >= MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) {
|
||||
flood_limited_query_count_++;
|
||||
return query->set_retry_after_error(60);
|
||||
return fail_query_flood_limit_exceeded(std::move(query));
|
||||
}
|
||||
count++;
|
||||
|
||||
@ -9616,6 +9610,15 @@ void Client::fail_query_closing(PromisedQueryPtr &&query) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::fail_query_flood_limit_exceeded(PromisedQueryPtr &&query) {
|
||||
flood_limited_query_count_++;
|
||||
td::create_actor<td::SleepActor>(
|
||||
"FailQueryFloodLimitExceededActor", 3.0,
|
||||
td::PromiseCreator::lambda(
|
||||
[query = std::move(query)](td::Result<td::Unit> result) mutable { query->set_retry_after_error(60); }))
|
||||
.release();
|
||||
}
|
||||
|
||||
Client::ClosingError Client::get_closing_error() {
|
||||
ClosingError result;
|
||||
result.retry_after = 0;
|
||||
|
@ -618,6 +618,8 @@ class Client final : public WebhookActor::Callback {
|
||||
|
||||
void fail_query_closing(PromisedQueryPtr &&query);
|
||||
|
||||
void fail_query_flood_limit_exceeded(PromisedQueryPtr &&query);
|
||||
|
||||
void fail_query_conflict(Slice message, PromisedQueryPtr &&query);
|
||||
|
||||
struct ClosingError {
|
||||
|
Loading…
Reference in New Issue
Block a user