2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Destory stats sessions after a timeout.

This commit is contained in:
John Preston
2023-11-11 21:20:09 +04:00
parent 1e6cf839e2
commit 9324ceeb24
8 changed files with 199 additions and 62 deletions

View File

@@ -114,6 +114,7 @@ constexpr auto kStickersByEmojiInvalidateTimeout = crl::time(6 * 1000);
constexpr auto kNotifySettingSaveTimeout = crl::time(1000);
constexpr auto kDialogsFirstLoad = 20;
constexpr auto kDialogsPerPage = 500;
constexpr auto kStatsSessionKillTimeout = 10 * crl::time(1000);
using PhotoFileLocationId = Data::PhotoFileLocationId;
using DocumentFileLocationId = Data::DocumentFileLocationId;
@@ -159,6 +160,7 @@ ApiWrap::ApiWrap(not_null<Main::Session*> session)
, _fileLoader(std::make_unique<TaskQueue>(kFileLoaderQueueStopTimeout))
, _topPromotionTimer([=] { refreshTopPromotion(); })
, _updateNotifyTimer([=] { sendNotifySettingsUpdates(); })
, _statsSessionKillTimer([=] { checkStatsSessions(); })
, _authorizations(std::make_unique<Api::Authorizations>(this))
, _attachedStickers(std::make_unique<Api::AttachedStickers>(this))
, _blockedPeers(std::make_unique<Api::BlockedPeers>(this))
@@ -4287,6 +4289,32 @@ void ApiWrap::saveSelfBio(const QString &text) {
}).send();
}
void ApiWrap::registerStatsRequest(MTP::DcId dcId, mtpRequestId id) {
_statsRequests[dcId].emplace(id);
}
void ApiWrap::unregisterStatsRequest(MTP::DcId dcId, mtpRequestId id) {
const auto i = _statsRequests.find(dcId);
Assert(i != end(_statsRequests));
const auto removed = i->second.remove(id);
Assert(removed);
if (i->second.empty()) {
_statsSessionKillTimer.callOnce(kStatsSessionKillTimeout);
}
}
void ApiWrap::checkStatsSessions() {
for (auto i = begin(_statsRequests); i != end(_statsRequests);) {
if (i->second.empty()) {
instance().killSession(
MTP::ShiftDcId(i->first, MTP::kStatsDcShift));
i = _statsRequests.erase(i);
} else {
++i;
}
}
}
Api::Authorizations &ApiWrap::authorizations() {
return *_authorizations;
}