Skip to content

Commit

Permalink
possible fix for sync button colour blue after sync
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dae committed Dec 21, 2020
1 parent c18ea8e commit 73679b0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pylib/anki/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pylib/anki/dbproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 73679b0

Please sign in to comment.