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:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user