Removed runHook calls from sync code

These hooks were only used on the client.
This commit is contained in:
Karsten Lehmann 2020-09-02 18:33:48 +02:00
parent 614f209f98
commit 0d8f3c6eea
No known key found for this signature in database
GPG Key ID: 6C34E8199743C270

View File

@ -16,7 +16,6 @@ from anki.utils import ids2str, intTime, platDesc, checksum, devMode
from anki.consts import * from anki.consts import *
from anki.config import ConfigManager from anki.config import ConfigManager
from anki.utils import versionWithBuild from anki.utils import versionWithBuild
from anki.hooks import runHook
import anki import anki
from anki.lang import ngettext from anki.lang import ngettext
@ -50,7 +49,6 @@ class Syncer(object):
self.col.save() self.col.save()
# step 1: login & metadata # step 1: login & metadata
runHook("sync", "login")
meta = self.server.meta() meta = self.server.meta()
self.col.log("rmeta", meta) self.col.log("rmeta", meta)
if not meta: if not meta:
@ -90,7 +88,6 @@ class Syncer(object):
self.col.log("basic check") self.col.log("basic check")
return "basicCheckFailed" return "basicCheckFailed"
# step 2: startup and deletions # step 2: startup and deletions
runHook("sync", "meta")
rrem = self.server.start(minUsn=self.minUsn, lnewer=self.lnewer) rrem = self.server.start(minUsn=self.minUsn, lnewer=self.lnewer)
# apply deletions to server # apply deletions to server
@ -107,25 +104,20 @@ class Syncer(object):
rchg = self.server.applyChanges(changes=lchg) rchg = self.server.applyChanges(changes=lchg)
self.mergeChanges(lchg, rchg) self.mergeChanges(lchg, rchg)
# step 3: stream large tables from server # step 3: stream large tables from server
runHook("sync", "server") while True:
while 1:
runHook("sync", "stream")
chunk = self.server.chunk() chunk = self.server.chunk()
self.col.log("server chunk", chunk) self.col.log("server chunk", chunk)
self.applyChunk(chunk=chunk) self.applyChunk(chunk=chunk)
if chunk['done']: if chunk['done']:
break break
# step 4: stream to server # step 4: stream to server
runHook("sync", "client") while True:
while 1:
runHook("sync", "stream")
chunk = self.chunk() chunk = self.chunk()
self.col.log("client chunk", chunk) self.col.log("client chunk", chunk)
self.server.applyChunk(chunk=chunk) self.server.applyChunk(chunk=chunk)
if chunk['done']: if chunk['done']:
break break
# step 5: sanity check # step 5: sanity check
runHook("sync", "sanity")
c = self.sanityCheck() c = self.sanityCheck()
ret = self.server.sanityCheck2(client=c) ret = self.server.sanityCheck2(client=c)
if ret['status'] != "ok": if ret['status'] != "ok":
@ -135,7 +127,6 @@ class Syncer(object):
self.col.save() self.col.save()
return "sanityCheckFailed" return "sanityCheckFailed"
# finalize # finalize
runHook("sync", "finalize")
mod = self.server.finish() mod = self.server.finish()
self.finish(mod) self.finish(mod)
return "success" return "success"
@ -449,7 +440,6 @@ class AnkiRequestsClient(object):
buf = io.BytesIO() buf = io.BytesIO()
for chunk in resp.iter_content(chunk_size=HTTP_BUF_SIZE): for chunk in resp.iter_content(chunk_size=HTTP_BUF_SIZE):
runHook("httpRecv", len(chunk))
buf.write(chunk) buf.write(chunk)
return buf.getvalue() return buf.getvalue()
@ -467,7 +457,7 @@ if os.environ.get("ANKI_NOVERIFYSSL"):
class _MonitoringFile(io.BufferedReader): class _MonitoringFile(io.BufferedReader):
def read(self, size=-1): def read(self, size=-1):
data = io.BufferedReader.read(self, HTTP_BUF_SIZE) data = io.BufferedReader.read(self, HTTP_BUF_SIZE)
runHook("httpSend", len(data))
return data return data
# HTTP syncing tools # HTTP syncing tools
@ -632,13 +622,11 @@ class FullSyncer(HttpSyncer):
self.col = col self.col = col
def download(self): def download(self):
runHook("sync", "download")
localNotEmpty = self.col.db.scalar("select 1 from cards") localNotEmpty = self.col.db.scalar("select 1 from cards")
self.col.close() self.col.close()
cont = self.req("download") cont = self.req("download")
tpath = self.col.path + ".tmp" tpath = self.col.path + ".tmp"
if cont == "upgradeRequired": if cont == "upgradeRequired":
runHook("sync", "upgradeRequired")
return return
open(tpath, "wb").write(cont) open(tpath, "wb").write(cont)
# check the received file is ok # check the received file is ok
@ -657,7 +645,6 @@ class FullSyncer(HttpSyncer):
def upload(self): def upload(self):
"True if upload successful." "True if upload successful."
runHook("sync", "upload")
# make sure it's ok before we try to upload # make sure it's ok before we try to upload
if self.col.db.scalar("pragma integrity_check") != "ok": if self.col.db.scalar("pragma integrity_check") != "ok":
return False return False