Remove manual Gzip flag specification in query creation; support uploaded files pack.

GitOrigin-RevId: 46ddfc230182615517eac7b611a79284559bd694
This commit is contained in:
levlam 2020-03-15 02:49:10 +03:00
parent 34973a5823
commit ad3c28932b
3 changed files with 18 additions and 15 deletions

View File

@ -277,12 +277,10 @@ Result<std::pair<NetQueryPtr, bool>> FileUploader::start_part(Part part, int32 p
if (big_flag_) {
auto query =
telegram_api::upload_saveBigFilePart(file_id_, part.id, local_is_ready_ ? part_count : -1, std::move(bytes));
net_query = G()->net_query_creator().create(create_storer(query), DcId::main(), NetQuery::Type::Upload,
NetQuery::AuthFlag::On, NetQuery::GzipFlag::Off);
net_query = G()->net_query_creator().create(create_storer(query), DcId::main(), NetQuery::Type::Upload);
} else {
auto query = telegram_api::upload_saveFilePart(file_id_, part.id, std::move(bytes));
net_query = G()->net_query_creator().create(create_storer(query), DcId::main(), NetQuery::Type::Upload,
NetQuery::AuthFlag::On, NetQuery::GzipFlag::Off);
net_query = G()->net_query_creator().create(create_storer(query), DcId::main(), NetQuery::Type::Upload);
}
net_query->file_type_ = narrow_cast<int32>(file_type_);
return std::make_pair(std::move(net_query), false);

View File

@ -14,19 +14,26 @@
namespace td {
NetQueryCreator::Ptr NetQueryCreator::create(uint64 id, const Storer &storer, DcId dc_id, NetQuery::Type type,
NetQuery::AuthFlag auth_flag, NetQuery::GzipFlag gzip_flag) {
NetQuery::AuthFlag auth_flag) {
BufferSlice slice(storer.size());
auto real_size = storer.store(slice.as_slice().ubegin());
LOG_CHECK(real_size == slice.size()) << real_size << " " << slice.size() << " "
<< format::as_hex_dump<4>(Slice(slice.as_slice()));
// TODO: magic constant
if (slice.size() < (1 << 8)) {
gzip_flag = NetQuery::GzipFlag::Off;
}
int32 tl_constructor = NetQuery::tl_magic(slice);
size_t MIN_GZIPPED_SIZE = 128;
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
size_t TESTED_SIZE = 1024;
BufferSlice compressed_part = gzencode(slice.as_slice().substr((slice.size() - TESTED_SIZE) / 2, TESTED_SIZE), 0.9);
if (compressed_part.empty()) {
gzip_flag = NetQuery::GzipFlag::Off;
}
}
if (gzip_flag == NetQuery::GzipFlag::On) {
// TODO: try to compress files?
BufferSlice compressed = gzencode(slice.as_slice(), 0.9);
if (compressed.empty()) {
gzip_flag = NetQuery::GzipFlag::Off;

View File

@ -35,13 +35,11 @@ class NetQueryCreator {
}
Ptr create(const Storer &storer, DcId dc_id = DcId::main(), NetQuery::Type type = NetQuery::Type::Common,
NetQuery::AuthFlag auth_flag = NetQuery::AuthFlag::On,
NetQuery::GzipFlag gzip_flag = NetQuery::GzipFlag::On) {
return create(UniqueId::next(), storer, dc_id, type, auth_flag, gzip_flag);
NetQuery::AuthFlag auth_flag = NetQuery::AuthFlag::On) {
return create(UniqueId::next(), storer, dc_id, type, auth_flag);
}
Ptr create(uint64 id, const Storer &storer, DcId dc_id = DcId::main(), NetQuery::Type type = NetQuery::Type::Common,
NetQuery::AuthFlag auth_flag = NetQuery::AuthFlag::On,
NetQuery::GzipFlag gzip_flag = NetQuery::GzipFlag::On);
NetQuery::AuthFlag auth_flag = NetQuery::AuthFlag::On);
private:
ObjectPool<NetQuery> object_pool_;