possible fix for sync button colour blue after sync

If the client's clock is behind AnkiWeb's, even by a few seconds,
we can end up with a situation where last_begin_at is updated after
the sync to a value less than the mtime we received from AnkiWeb,
causing the collection to be saved, which bumps the modtime.

Work around this by recording mtime at begin() time, and seeing if it
has changed in either direction.

Thanks to Rumo, who did the hard work looking into it:
https://forums.ankiweb.net/t/why-is-my-sync-button-blue/2078/21
This commit is contained in:
Damien Elmes 2020-12-21 19:24:04 +10:00
parent c18ea8ef78
commit 73679b03e7
2 changed files with 2 additions and 2 deletions

View File

@ -196,7 +196,7 @@ class Collection:
# Until we can move away from long-running transactions, the Python
# code needs to know if transaction should be committed, so we need
# to check if the backend updated the modification time.
return self.db.last_begin_at <= self.mod
return self.db.last_begin_at != self.mod
def save(
self, name: Optional[str] = None, mod: Optional[int] = None, trx: bool = True

View File

@ -30,7 +30,7 @@ class DBProxy:
###############
def begin(self) -> None:
self.last_begin_at = anki.utils.intTime(1000)
self.last_begin_at = self.scalar("select mod from col")
self._backend.db_begin()
def commit(self) -> None: