From e8f274ee843111eae7f91679cbf86d782504fb63 Mon Sep 17 00:00:00 2001 From: flan Date: Mon, 30 Dec 2019 02:21:42 +0100 Subject: [PATCH] Fix long media sync times on AnkiDroid Based on PR #44 by Johannes Schirm . The code is pretty much the same, but with usn used instead of mtime for determining which media files have changed since last sync. Relevant excerpt from #44: > The server was always sending metadata for all files in the > collection as a response to the mediaChanges operation. Because > AnkiDroid then calculates checksums for all these files (just to > notice that they actually haven't changed), it took larger > collections very long to sync after every media change. With this > fix, only the number of files indicated by usn - lastUsn (and > mtime) are considered for each sync. Fixes #26, closes #44. --- ankisyncd/sync_app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ankisyncd/sync_app.py b/ankisyncd/sync_app.py index 9553c24..5972335 100644 --- a/ankisyncd/sync_app.py +++ b/ankisyncd/sync_app.py @@ -318,11 +318,11 @@ class SyncMediaHandler: def mediaChanges(self, lastUsn): result = [] - usn = self.col.media.lastUsn() + server_lastUsn = self.col.media.lastUsn() fname = csum = None - if lastUsn < usn or lastUsn == 0: - for fname,usn,csum, in self.col.media.db.execute("select fname,usn,csum from media"): + if lastUsn < server_lastUsn or lastUsn == 0: + for fname,usn,csum, in self.col.media.db.execute("select fname,usn,csum from media order by usn desc limit ?", server_lastUsn - lastUsn): result.append([fname, usn, csum]) return {'data': result, 'err': ''}