mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
feat: upload speed boost
Co-authored-by: RadRussianRus <radrussianrus@gmail.com>
This commit is contained in:
parent
8c41a69e67
commit
74196732ac
9 changed files with 76 additions and 13 deletions
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -632,6 +632,28 @@ void SetupQoLToggles(not_null<Ui::VerticalLayout *> 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(),
|
||||
|
|
|
@ -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<DedicatedLoader::File> 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<Main::Session> 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(); });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 <UploadSessionsCount(); ++i) {
|
||||
sentSizes[i] = 0;
|
||||
}
|
||||
|
||||
|
@ -395,13 +411,13 @@ void Uploader::notifyFailed(FullMsgId id, const File &file) {
|
|||
}
|
||||
|
||||
void Uploader::stopSessions() {
|
||||
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
||||
for (int i = 0; i < UploadSessionsCount(); ++i) {
|
||||
_api->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;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ private:
|
|||
base::flat_map<mtpRequestId, int32> docRequestsSent;
|
||||
base::flat_map<mtpRequestId, int32> 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue