Send dependent requests in bunches.

This commit is contained in:
John Preston 2021-07-06 11:31:01 +03:00
parent e28fb1211e
commit a0540e0486

View file

@ -1017,32 +1017,42 @@ void Instance::Private::unregisterRequest(mtpRequestId requestId) {
_requestsByDc.erase(requestId); _requestsByDc.erase(requestId);
} }
{ {
QMutexLocker locker(&_dependentRequestsLock); auto toRemove = base::flat_set<mtpRequestId>();
for (auto i = begin(_dependentRequests); i != end(_dependentRequests);) { auto toResend = base::flat_set<mtpRequestId>();
if (i->first == requestId) {
i = _dependentRequests.erase(i);
} else if (i->second == requestId) {
const auto resendingId = i->first;
i = _dependentRequests.erase(i);
if (const auto shiftedDcId = queryRequestByDc(resendingId)) { toRemove.emplace(requestId);
SerializedRequest request;
{ QMutexLocker locker(&_dependentRequestsLock);
QReadLocker locker(&_requestMapLock);
auto it = _requestMap.find(resendingId); auto handling = 0;
if (it == _requestMap.cend()) { do {
LOG(("MTP Error: could not find dependent request %1").arg(resendingId)); handling = toResend.size();
return; for (const auto [resendingId, afterId] : _dependentRequests) {
} if (toRemove.contains(afterId)) {
request = it->second; toRemove.emplace(resendingId);
} toResend.emplace(resendingId);
request->after = SerializedRequest();
const auto session = getSession(qAbs(*shiftedDcId));
request->needsLayer = true;
session->sendPrepared(request);
} }
} else { }
++i; } while (handling != toResend.size());
for (const auto removingId : toRemove) {
_dependentRequests.remove(removingId);
}
locker.unlock();
for (const auto resendingId : toResend) {
if (const auto shiftedDcId = queryRequestByDc(resendingId)) {
SerializedRequest request;
{
QReadLocker locker(&_requestMapLock);
auto it = _requestMap.find(resendingId);
if (it == _requestMap.cend()) {
LOG(("MTP Error: could not find dependent request %1").arg(resendingId));
return;
}
request = it->second;
}
getSession(qAbs(*shiftedDcId))->sendPrepared(request);
} }
} }
} }
@ -1405,9 +1415,7 @@ bool Instance::Private::onErrorDefault(
} }
if (!request->after) { if (!request->after) {
const auto session = getSession(qAbs(dcWithShift)); getSession(qAbs(dcWithShift))->sendPrepared(request);
request->needsLayer = true;
session->sendPrepared(request);
} else { } else {
QMutexLocker locker(&_dependentRequestsLock); QMutexLocker locker(&_dependentRequestsLock);
_dependentRequests.emplace(requestId, request->after->requestId); _dependentRequests.emplace(requestId, request->after->requestId);