From 73679b03e73e4df23ad59fdccb6cfb2a7fb50a8e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 21 Dec 2020 19:24:04 +1000 Subject: [PATCH] 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 --- pylib/anki/collection.py | 2 +- pylib/anki/dbproxy.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 77eab871625..6ac76981413 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -196,7 +196,7 @@ def modified_after_begin(self) -> bool: # 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 diff --git a/pylib/anki/dbproxy.py b/pylib/anki/dbproxy.py index e555c74b359..1a9c024ffea 100644 --- a/pylib/anki/dbproxy.py +++ b/pylib/anki/dbproxy.py @@ -30,7 +30,7 @@ def __init__(self, backend: anki.rsbackend.RustBackend) -> None: ############### 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: