mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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_DisableSimilarChannels" = "Disable similar channels";
|
||||||
"ayu_CollapseSimilarChannels" = "Collapse similar channels";
|
"ayu_CollapseSimilarChannels" = "Collapse similar channels";
|
||||||
"ayu_HideSimilarChannelsTab" = "Hide similar channels tab";
|
"ayu_HideSimilarChannelsTab" = "Hide similar channels tab";
|
||||||
|
"ayu_UploadSpeedBoostPC" = "Upload speed boost";
|
||||||
"ayu_MainFont" = "Application font";
|
"ayu_MainFont" = "Application font";
|
||||||
"ayu_MonospaceFont" = "Monospace font";
|
"ayu_MonospaceFont" = "Monospace font";
|
||||||
"ayu_FontDefault" = "Default";
|
"ayu_FontDefault" = "Default";
|
||||||
|
|
|
@ -270,6 +270,11 @@ void AyuGramSettings::set_hideSimilarChannels(bool val)
|
||||||
hideSimilarChannels = val;
|
hideSimilarChannels = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_uploadSpeedBoost(bool val)
|
||||||
|
{
|
||||||
|
uploadSpeedBoost = val;
|
||||||
|
}
|
||||||
|
|
||||||
void AyuGramSettings::set_disableNotificationsDelay(bool val)
|
void AyuGramSettings::set_disableNotificationsDelay(bool val)
|
||||||
{
|
{
|
||||||
disableNotificationsDelay = val;
|
disableNotificationsDelay = val;
|
||||||
|
|
|
@ -123,6 +123,9 @@ public:
|
||||||
bool disableStories;
|
bool disableStories;
|
||||||
bool collapseSimilarChannels;
|
bool collapseSimilarChannels;
|
||||||
bool hideSimilarChannels;
|
bool hideSimilarChannels;
|
||||||
|
|
||||||
|
bool uploadSpeedBoost;
|
||||||
|
|
||||||
bool disableNotificationsDelay;
|
bool disableNotificationsDelay;
|
||||||
bool localPremium;
|
bool localPremium;
|
||||||
bool copyUsernameAsLink;
|
bool copyUsernameAsLink;
|
||||||
|
@ -181,6 +184,9 @@ public:
|
||||||
void set_disableStories(bool val);
|
void set_disableStories(bool val);
|
||||||
void set_collapseSimilarChannels(bool val);
|
void set_collapseSimilarChannels(bool val);
|
||||||
void set_hideSimilarChannels(bool val);
|
void set_hideSimilarChannels(bool val);
|
||||||
|
|
||||||
|
void set_uploadSpeedBoost(bool val);
|
||||||
|
|
||||||
void set_disableNotificationsDelay(bool val);
|
void set_disableNotificationsDelay(bool val);
|
||||||
void set_localPremium(bool val);
|
void set_localPremium(bool val);
|
||||||
void set_copyUsernameAsLink(bool val);
|
void set_copyUsernameAsLink(bool val);
|
||||||
|
@ -236,6 +242,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
|
||||||
disableStories,
|
disableStories,
|
||||||
collapseSimilarChannels,
|
collapseSimilarChannels,
|
||||||
hideSimilarChannels,
|
hideSimilarChannels,
|
||||||
|
uploadSpeedBoost,
|
||||||
disableNotificationsDelay,
|
disableNotificationsDelay,
|
||||||
localPremium,
|
localPremium,
|
||||||
copyUsernameAsLink,
|
copyUsernameAsLink,
|
||||||
|
|
|
@ -632,6 +632,28 @@ void SetupQoLToggles(not_null<Ui::VerticalLayout *> container)
|
||||||
AddDivider(container);
|
AddDivider(container);
|
||||||
AddSkip(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(
|
AddButtonWithIcon(
|
||||||
container,
|
container,
|
||||||
tr::ayu_DisableNotificationsDelay(),
|
tr::ayu_DisableNotificationsDelay(),
|
||||||
|
|
|
@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
|
|
||||||
|
// AyuGram includes
|
||||||
|
#include "ayu/ayu_settings.h"
|
||||||
|
|
||||||
|
|
||||||
namespace MTP {
|
namespace MTP {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -80,6 +84,12 @@ std::optional<DedicatedLoader::File> ParseFile(
|
||||||
return DedicatedLoader::File{ name, size, fields.vdc_id().v, location };
|
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
|
} // namespace
|
||||||
|
|
||||||
WeakInstance::WeakInstance(base::weak_ptr<Main::Session> session)
|
WeakInstance::WeakInstance(base::weak_ptr<Main::Session> session)
|
||||||
|
@ -310,7 +320,7 @@ void DedicatedLoader::startLoading() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DedicatedLoader::sendRequest() {
|
void DedicatedLoader::sendRequest() {
|
||||||
if (_requests.size() >= kRequestsCount || _offset >= _size) {
|
if (_requests.size() >= RequestCount() || _offset >= _size) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto offset = _offset;
|
const auto offset = _offset;
|
||||||
|
@ -326,7 +336,7 @@ void DedicatedLoader::sendRequest() {
|
||||||
MTP::updaterDcId(_dcId));
|
MTP::updaterDcId(_dcId));
|
||||||
_offset += kChunkSize;
|
_offset += kChunkSize;
|
||||||
|
|
||||||
if (_requests.size() < kRequestsCount) {
|
if (_requests.size() < RequestCount()) {
|
||||||
base::call_delayed(kNextRequestDelay, this, [=] { sendRequest(); });
|
base::call_delayed(kNextRequestDelay, this, [=] { sendRequest(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class AbstractDedicatedLoader : public base::has_weak_ptr {
|
||||||
public:
|
public:
|
||||||
AbstractDedicatedLoader(const QString &filepath, int chunkSize);
|
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;
|
static constexpr auto kMaxFileSize = 256 * 1024 * 1024;
|
||||||
|
|
||||||
struct Progress {
|
struct Progress {
|
||||||
|
|
|
@ -42,6 +42,8 @@ constexpr ShiftedDcId groupCallStreamDcId(DcId dcId) {
|
||||||
|
|
||||||
constexpr auto kUploadSessionsCount = 2;
|
constexpr auto kUploadSessionsCount = 2;
|
||||||
|
|
||||||
|
constexpr auto kUploadSessionsCountMax = 8;
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
|
constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
|
||||||
|
@ -92,7 +94,7 @@ inline DcId getTemporaryIdFromRealDcId(ShiftedDcId shiftedDcId) {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
|
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);
|
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
|
// send(req, callbacks, MTP::uploadDcId(index)) - for upload shifted dc id
|
||||||
// uploading always to the main dc so BareDcId(result) == 0
|
// uploading always to the main dc so BareDcId(result) == 0
|
||||||
inline ShiftedDcId uploadDcId(int index) {
|
inline ShiftedDcId uploadDcId(int index) {
|
||||||
Expects(index >= 0 && index < kUploadSessionsCount);
|
Expects(index >= 0 && index < kUploadSessionsCountMax);
|
||||||
|
|
||||||
return details::uploadDcId(0, index);
|
return details::uploadDcId(0, index);
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr bool isUploadDcId(ShiftedDcId shiftedDcId) {
|
constexpr bool isUploadDcId(ShiftedDcId shiftedDcId) {
|
||||||
return (shiftedDcId >= details::uploadDcId(0, 0))
|
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) {
|
inline ShiftedDcId destroyKeyNextDcId(ShiftedDcId shiftedDcId) {
|
||||||
|
|
|
@ -23,6 +23,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
|
||||||
|
// AyuGram includes
|
||||||
|
#include "ayu/ayu_settings.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Storage {
|
namespace Storage {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -56,6 +60,18 @@ constexpr auto kKillSessionTimeout = 15 * crl::time(1000);
|
||||||
return Core::IsMimeSticker(mime) ? "WEBP" : "JPG";
|
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
|
} // namespace
|
||||||
|
|
||||||
struct Uploader::File {
|
struct Uploader::File {
|
||||||
|
@ -368,7 +384,7 @@ void Uploader::currentFailed() {
|
||||||
dcMap.clear();
|
dcMap.clear();
|
||||||
uploadingId = FullMsgId();
|
uploadingId = FullMsgId();
|
||||||
sentSize = 0;
|
sentSize = 0;
|
||||||
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
for (int i = 0; i <UploadSessionsCount(); ++i) {
|
||||||
sentSizes[i] = 0;
|
sentSizes[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,13 +411,13 @@ void Uploader::notifyFailed(FullMsgId id, const File &file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uploader::stopSessions() {
|
void Uploader::stopSessions() {
|
||||||
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
for (int i = 0; i < UploadSessionsCount(); ++i) {
|
||||||
_api->instance().stopSession(MTP::uploadDcId(i));
|
_api->instance().stopSession(MTP::uploadDcId(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uploader::sendNext() {
|
void Uploader::sendNext() {
|
||||||
if (sentSize >= kMaxUploadFileParallelSize || _pausedId.msg) {
|
if (sentSize >= (UploadSessionsCount() * 512 * 1024) || _pausedId.msg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +442,7 @@ void Uploader::sendNext() {
|
||||||
auto &uploadingData = i->second;
|
auto &uploadingData = i->second;
|
||||||
|
|
||||||
auto todc = 0;
|
auto todc = 0;
|
||||||
for (auto dc = 1; dc != MTP::kUploadSessionsCount; ++dc) {
|
for (auto dc = 1; dc != UploadSessionsCount(); ++dc) {
|
||||||
if (sentSizes[dc] < sentSizes[todc]) {
|
if (sentSizes[dc] < sentSizes[todc]) {
|
||||||
todc = dc;
|
todc = dc;
|
||||||
}
|
}
|
||||||
|
@ -619,7 +635,7 @@ void Uploader::sendNext() {
|
||||||
|
|
||||||
parts.erase(part);
|
parts.erase(part);
|
||||||
}
|
}
|
||||||
_nextTimer.callOnce(kUploadRequestInterval);
|
_nextTimer.callOnce(crl::time(UploadSessionsInterval()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uploader::cancel(const FullMsgId &msgId) {
|
void Uploader::cancel(const FullMsgId &msgId) {
|
||||||
|
@ -676,7 +692,7 @@ void Uploader::clear() {
|
||||||
cancelRequests();
|
cancelRequests();
|
||||||
dcMap.clear();
|
dcMap.clear();
|
||||||
sentSize = 0;
|
sentSize = 0;
|
||||||
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
for (int i = 0; i < UploadSessionsCount(); ++i) {
|
||||||
_api->instance().stopSession(MTP::uploadDcId(i));
|
_api->instance().stopSession(MTP::uploadDcId(i));
|
||||||
sentSizes[i] = 0;
|
sentSizes[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ private:
|
||||||
base::flat_map<mtpRequestId, int32> docRequestsSent;
|
base::flat_map<mtpRequestId, int32> docRequestsSent;
|
||||||
base::flat_map<mtpRequestId, int32> dcMap;
|
base::flat_map<mtpRequestId, int32> dcMap;
|
||||||
uint32 sentSize = 0; // FileSize: Right now any file size fits 32 bit.
|
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 uploadingId;
|
||||||
FullMsgId _pausedId;
|
FullMsgId _pausedId;
|
||||||
|
|
Loading…
Add table
Reference in a new issue