2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-04 16:45:12 +00:00

Improve queued by pts updates handling.

The updates are ordered by pts and applied in the correct order.
Also some pts-dependent updates handling was moved to ApiWrap.
This commit is contained in:
John Preston
2017-07-14 14:54:47 +03:00
parent 101ec9a1c1
commit 949104d879
6 changed files with 273 additions and 223 deletions

View File

@@ -983,8 +983,8 @@ void ChannelData::setRestrictedRights(const MTPChannelBannedRights &rights) {
Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged);
}
uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue) {
return _queue.insert(uint64(uint32(_last)) << 32 | uint64(uint32(_count)), queue).key();
uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue, int32 pts) {
return _queue.insert(uint64(uint32(pts)) << 32 | (++_skippedKey), queue).key();
}
void PtsWaiter::setWaitingForSkipped(ChannelData *channel, int32 ms) {
@@ -1022,13 +1022,13 @@ void PtsWaiter::applySkippedUpdates(ChannelData *channel) {
setWaitingForSkipped(channel, -1);
if (!App::main() || _queue.isEmpty()) return;
if (!App::api() || _queue.isEmpty()) return;
++_applySkippedLevel;
for (QMap<uint64, PtsSkippedQueue>::const_iterator i = _queue.cbegin(), e = _queue.cend(); i != e; ++i) {
switch (i.value()) {
case SkippedUpdate: App::main()->feedUpdate(_updateQueue.value(i.key())); break;
case SkippedUpdates: App::main()->feedUpdates(_updatesQueue.value(i.key())); break;
case SkippedUpdate: App::api()->applyUpdateNoPtsCheck(_updateQueue.value(i.key())); break;
case SkippedUpdates: App::api()->applyUpdatesNoPtsCheck(_updatesQueue.value(i.key())); break;
}
}
--_applySkippedLevel;
@@ -1042,15 +1042,6 @@ void PtsWaiter::clearSkippedUpdates() {
_applySkippedLevel = 0;
}
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count) {
if (_requesting || _applySkippedLevel) {
return true;
} else if (pts <= _good && count > 0) {
return false;
}
return check(channel, pts, count);
}
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) {
if (_requesting || _applySkippedLevel) {
return true;
@@ -1059,7 +1050,7 @@ bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPU
} else if (check(channel, pts, count)) {
return true;
}
_updatesQueue.insert(ptsKey(SkippedUpdates), updates);
_updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates);
return false;
}
@@ -1071,10 +1062,55 @@ bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPU
} else if (check(channel, pts, count)) {
return true;
}
_updateQueue.insert(ptsKey(SkippedUpdate), update);
_updateQueue.insert(ptsKey(SkippedUpdate, pts), update);
return false;
}
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count) {
if (_requesting || _applySkippedLevel) {
return true;
} else if (pts <= _good && count > 0) {
return false;
}
return check(channel, pts, count);
}
bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) {
if (!updated(channel, pts, count, updates)) {
return false;
}
if (!_waitingForSkipped || _queue.isEmpty()) {
// Optimization - no need to put in queue and back.
App::api()->applyUpdatesNoPtsCheck(updates);
} else {
_updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates);
applySkippedUpdates(channel);
}
return true;
}
bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) {
if (!updated(channel, pts, count, update)) {
return false;
}
if (!_waitingForSkipped || _queue.isEmpty()) {
// Optimization - no need to put in queue and back.
App::api()->applyUpdateNoPtsCheck(update);
} else {
_updateQueue.insert(ptsKey(SkippedUpdate, pts), update);
applySkippedUpdates(channel);
}
return true;
}
bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count) {
if (!updated(channel, pts, count)) {
return false;
}
applySkippedUpdates(channel);
return true;
}
bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) { // return false if need to save that update and apply later
if (!inited()) {
init(pts);