diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 530d5da4e..576546ccd 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4772,6 +4772,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_DisableSimilarChannels" = "Disable similar channels"; "ayu_CollapseSimilarChannels" = "Collapse similar channels"; "ayu_HideSimilarChannelsTab" = "Hide similar channels tab"; +"ayu_UploadSpeedBoostPC" = "Upload speed boost"; "ayu_MainFont" = "Application font"; "ayu_MonospaceFont" = "Monospace font"; "ayu_FontDefault" = "Default"; diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 8ba23972c..93547269b 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -270,6 +270,11 @@ void AyuGramSettings::set_hideSimilarChannels(bool val) hideSimilarChannels = val; } +void AyuGramSettings::set_uploadSpeedBoost(bool val) +{ + uploadSpeedBoost = val; +} + void AyuGramSettings::set_disableNotificationsDelay(bool val) { disableNotificationsDelay = val; diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 801c01d43..490e25c1b 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -123,6 +123,9 @@ public: bool disableStories; bool collapseSimilarChannels; bool hideSimilarChannels; + + bool uploadSpeedBoost; + bool disableNotificationsDelay; bool localPremium; bool copyUsernameAsLink; @@ -181,6 +184,9 @@ public: void set_disableStories(bool val); void set_collapseSimilarChannels(bool val); void set_hideSimilarChannels(bool val); + + void set_uploadSpeedBoost(bool val); + void set_disableNotificationsDelay(bool val); void set_localPremium(bool val); void set_copyUsernameAsLink(bool val); @@ -236,6 +242,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( disableStories, collapseSimilarChannels, hideSimilarChannels, + uploadSpeedBoost, disableNotificationsDelay, localPremium, copyUsernameAsLink, diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 6717ea9ed..bb6b1b2d0 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -632,6 +632,28 @@ void SetupQoLToggles(not_null container) AddDivider(container); AddSkip(container); + AddButtonWithIcon( + container, + tr::ayu_UploadSpeedBoostPC(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->uploadSpeedBoost) + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return (enabled != settings->uploadSpeedBoost); + }) | start_with_next( + [=](bool enabled) + { + settings->set_uploadSpeedBoost(enabled); + AyuSettings::save(); + }, container->lifetime()); + + AddSkip(container); + AddDivider(container); + AddSkip(container); + AddButtonWithIcon( container, tr::ayu_DisableNotificationsDelay(), diff --git a/Telegram/SourceFiles/mtproto/dedicated_file_loader.cpp b/Telegram/SourceFiles/mtproto/dedicated_file_loader.cpp index 676aa047c..13a04f78b 100644 --- a/Telegram/SourceFiles/mtproto/dedicated_file_loader.cpp +++ b/Telegram/SourceFiles/mtproto/dedicated_file_loader.cpp @@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "base/call_delayed.h" +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace MTP { namespace { @@ -80,6 +84,12 @@ std::optional ParseFile( return DedicatedLoader::File{ name, size, fields.vdc_id().v, location }; } +int RequestCount() { + const auto settings = &AyuSettings::getInstance(); + static const auto count = settings->uploadSpeedBoost ? 8 : 2; + return count; +} + } // namespace WeakInstance::WeakInstance(base::weak_ptr session) @@ -310,7 +320,7 @@ void DedicatedLoader::startLoading() { } void DedicatedLoader::sendRequest() { - if (_requests.size() >= kRequestsCount || _offset >= _size) { + if (_requests.size() >= RequestCount() || _offset >= _size) { return; } const auto offset = _offset; @@ -326,7 +336,7 @@ void DedicatedLoader::sendRequest() { MTP::updaterDcId(_dcId)); _offset += kChunkSize; - if (_requests.size() < kRequestsCount) { + if (_requests.size() < RequestCount()) { base::call_delayed(kNextRequestDelay, this, [=] { sendRequest(); }); } } diff --git a/Telegram/SourceFiles/mtproto/dedicated_file_loader.h b/Telegram/SourceFiles/mtproto/dedicated_file_loader.h index 4a4e7eb24..eee56303a 100644 --- a/Telegram/SourceFiles/mtproto/dedicated_file_loader.h +++ b/Telegram/SourceFiles/mtproto/dedicated_file_loader.h @@ -48,7 +48,7 @@ class AbstractDedicatedLoader : public base::has_weak_ptr { public: AbstractDedicatedLoader(const QString &filepath, int chunkSize); - static constexpr auto kChunkSize = 128 * 1024; + static constexpr auto kChunkSize = 128 * 1024 * 8; static constexpr auto kMaxFileSize = 256 * 1024 * 1024; struct Progress { diff --git a/Telegram/SourceFiles/mtproto/facade.h b/Telegram/SourceFiles/mtproto/facade.h index 6f31960da..989fdad4b 100644 --- a/Telegram/SourceFiles/mtproto/facade.h +++ b/Telegram/SourceFiles/mtproto/facade.h @@ -42,6 +42,8 @@ constexpr ShiftedDcId groupCallStreamDcId(DcId dcId) { constexpr auto kUploadSessionsCount = 2; +constexpr auto kUploadSessionsCountMax = 8; + namespace details { constexpr ShiftedDcId downloadDcId(DcId dcId, int index) { @@ -92,7 +94,7 @@ inline DcId getTemporaryIdFromRealDcId(ShiftedDcId shiftedDcId) { namespace details { constexpr ShiftedDcId uploadDcId(DcId dcId, int index) { - static_assert(kUploadSessionsCount < kMaxMediaDcCount, "Too large MTPUploadSessionsCount!"); + static_assert(kUploadSessionsCountMax < kMaxMediaDcCount, "Too large MTPUploadSessionsCount!"); return ShiftDcId(dcId, kBaseUploadDcShift + index); }; @@ -101,14 +103,14 @@ constexpr ShiftedDcId uploadDcId(DcId dcId, int index) { // send(req, callbacks, MTP::uploadDcId(index)) - for upload shifted dc id // uploading always to the main dc so BareDcId(result) == 0 inline ShiftedDcId uploadDcId(int index) { - Expects(index >= 0 && index < kUploadSessionsCount); + Expects(index >= 0 && index < kUploadSessionsCountMax); return details::uploadDcId(0, index); }; constexpr bool isUploadDcId(ShiftedDcId shiftedDcId) { return (shiftedDcId >= details::uploadDcId(0, 0)) - && (shiftedDcId < details::uploadDcId(0, kUploadSessionsCount - 1) + kDcShift); + && (shiftedDcId < details::uploadDcId(0, kUploadSessionsCountMax - 1) + kDcShift); } inline ShiftedDcId destroyKeyNextDcId(ShiftedDcId shiftedDcId) { diff --git a/Telegram/SourceFiles/storage/file_upload.cpp b/Telegram/SourceFiles/storage/file_upload.cpp index f2a014f7e..1135b6a7d 100644 --- a/Telegram/SourceFiles/storage/file_upload.cpp +++ b/Telegram/SourceFiles/storage/file_upload.cpp @@ -23,6 +23,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "apiwrap.h" +// AyuGram includes +#include "ayu/ayu_settings.h" + + namespace Storage { namespace { @@ -56,6 +60,18 @@ constexpr auto kKillSessionTimeout = 15 * crl::time(1000); return Core::IsMimeSticker(mime) ? "WEBP" : "JPG"; } +int UploadSessionsCount() { + const auto settings = &AyuSettings::getInstance(); + static const auto count = settings->uploadSpeedBoost ? 8 : 2; + return count; +} + +int UploadSessionsInterval() { + const auto settings = &AyuSettings::getInstance(); + static const auto interval = settings->uploadSpeedBoost ? 25 : kUploadRequestInterval; + return interval; +} + } // namespace struct Uploader::File { @@ -368,7 +384,7 @@ void Uploader::currentFailed() { dcMap.clear(); uploadingId = FullMsgId(); sentSize = 0; - for (int i = 0; i < MTP::kUploadSessionsCount; ++i) { + for (int i = 0; i instance().stopSession(MTP::uploadDcId(i)); } } void Uploader::sendNext() { - if (sentSize >= kMaxUploadFileParallelSize || _pausedId.msg) { + if (sentSize >= (UploadSessionsCount() * 512 * 1024) || _pausedId.msg) { return; } @@ -426,7 +442,7 @@ void Uploader::sendNext() { auto &uploadingData = i->second; auto todc = 0; - for (auto dc = 1; dc != MTP::kUploadSessionsCount; ++dc) { + for (auto dc = 1; dc != UploadSessionsCount(); ++dc) { if (sentSizes[dc] < sentSizes[todc]) { todc = dc; } @@ -619,7 +635,7 @@ void Uploader::sendNext() { parts.erase(part); } - _nextTimer.callOnce(kUploadRequestInterval); + _nextTimer.callOnce(crl::time(UploadSessionsInterval())); } void Uploader::cancel(const FullMsgId &msgId) { @@ -676,7 +692,7 @@ void Uploader::clear() { cancelRequests(); dcMap.clear(); sentSize = 0; - for (int i = 0; i < MTP::kUploadSessionsCount; ++i) { + for (int i = 0; i < UploadSessionsCount(); ++i) { _api->instance().stopSession(MTP::uploadDcId(i)); sentSizes[i] = 0; } diff --git a/Telegram/SourceFiles/storage/file_upload.h b/Telegram/SourceFiles/storage/file_upload.h index de5a84a19..7e4a83fc6 100644 --- a/Telegram/SourceFiles/storage/file_upload.h +++ b/Telegram/SourceFiles/storage/file_upload.h @@ -127,7 +127,7 @@ private: base::flat_map docRequestsSent; base::flat_map dcMap; uint32 sentSize = 0; // FileSize: Right now any file size fits 32 bit. - uint32 sentSizes[MTP::kUploadSessionsCount] = { 0 }; + uint32 sentSizes[MTP::kUploadSessionsCountMax] = { 0 }; FullMsgId uploadingId; FullMsgId _pausedId;