Increase min_gzipped_size for bots.

This commit is contained in:
levlam 2023-05-10 02:06:24 +03:00
parent 59fcab80a1
commit 37c46b8b12

View File

@ -38,10 +38,27 @@ NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &fun
LOG_CHECK(real_size == slice.size()) << real_size << " " << slice.size() << " "
<< format::as_hex_dump<4>(slice.as_slice());
size_t min_gzipped_size = 128;
int32 tl_constructor = function.get_id();
int32 total_timeout_limit = 60;
size_t MIN_GZIPPED_SIZE = 128;
auto gzip_flag = slice.size() < MIN_GZIPPED_SIZE ? NetQuery::GzipFlag::Off : NetQuery::GzipFlag::On;
if (!G()->close_flag()) {
auto td = G()->td();
if (!td.empty()) {
auto auth_manager = td.get_actor_unsafe()->auth_manager_.get();
if (auth_manager != nullptr && auth_manager->is_bot()) {
total_timeout_limit = 8;
min_gzipped_size = 1024;
}
if ((auth_manager == nullptr || !auth_manager->was_authorized()) && auth_flag == NetQuery::AuthFlag::On &&
tl_constructor != telegram_api::auth_exportAuthorization::ID &&
tl_constructor != telegram_api::auth_bindTempAuthKey::ID) {
LOG(ERROR) << "Send query before authorization: " << to_string(function);
}
}
}
auto gzip_flag = slice.size() < min_gzipped_size ? NetQuery::GzipFlag::Off : NetQuery::GzipFlag::On;
if (slice.size() >= 16384) {
// test compression ratio for the middle part
// if it is less than 0.9, then try to compress the whole request
@ -60,21 +77,6 @@ NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &fun
}
}
int32 total_timeout_limit = 60;
if (!G()->close_flag()) {
auto td = G()->td();
if (!td.empty()) {
auto auth_manager = td.get_actor_unsafe()->auth_manager_.get();
if (auth_manager != nullptr && auth_manager->is_bot()) {
total_timeout_limit = 8;
}
if ((auth_manager == nullptr || !auth_manager->was_authorized()) && auth_flag == NetQuery::AuthFlag::On &&
tl_constructor != telegram_api::auth_exportAuthorization::ID &&
tl_constructor != telegram_api::auth_bindTempAuthKey::ID) {
LOG(ERROR) << "Send query before authorization: " << to_string(function);
}
}
}
auto query =
object_pool_.create(NetQuery::State::Query, id, std::move(slice), BufferSlice(), dc_id, type, auth_flag,
gzip_flag, tl_constructor, total_timeout_limit, net_query_stats_.get(), std::move(chain_ids));