send tz offset at start of sync; allow passing in offset at collection creation

This commit is contained in:
Damien Elmes 2019-12-27 19:40:59 +10:00
parent 92673c99d8
commit 683edeeb07
3 changed files with 23 additions and 9 deletions

View File

@ -81,7 +81,11 @@ class _Collection:
backend: Backend
def __init__(
self, db: DB, backend: Backend, server: bool = False, log: bool = False
self,
db: DB,
backend: Backend,
server: Optional["anki.storage.ServerData"] = None,
log: bool = False,
) -> None:
self.backend = backend
self._debugLog = log
@ -92,7 +96,7 @@ class _Collection:
self.server = server
self._lastSave = time.time()
self.clearUndo()
self.media = MediaManager(self, server)
self.media = MediaManager(self, server is not None)
self.models = ModelManager(self)
self.decks = DeckManager(self)
self.tags = TagManager(self)
@ -132,6 +136,8 @@ class _Collection:
self.sched = V2Scheduler(self)
if not self.server:
self.conf["localOffset"] = self.sched.timezoneOffset()
elif self.server.minutes_west is not None:
self.conf["localOffset"] = self.server.minutes_west
def changeSchedulerVer(self, ver: int) -> None:
if ver == self.schedVer():

View File

@ -6,7 +6,7 @@ import copy
import json
import os
import re
from typing import Any, Dict, Tuple
from typing import Any, Dict, Optional, Tuple
from anki.backend import Backend
from anki.collection import _Collection
@ -23,8 +23,12 @@ from anki.stdmodels import (
from anki.utils import intTime, isWin
class ServerData:
minutes_west: Optional[int]
def Collection(
path: str, lock: bool = True, server: bool = False, log: bool = False
path: str, lock: bool = True, server: Optional[ServerData] = None, log: bool = False
) -> _Collection:
"Open a new or existing collection. Path must be unicode."
backend = Backend()

View File

@ -36,7 +36,7 @@ class UnexpectedSchemaChange(Exception):
class Syncer:
cursor: Optional[sqlite3.Cursor]
def __init__(self, col, server=None) -> None:
def __init__(self, col: "anki.storage._Collection", server=None) -> None:
self.col = col
self.server = server
@ -95,7 +95,9 @@ class Syncer:
return "basicCheckFailed"
# 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, offset=self.col.localOffset()
)
# apply deletions to server
lgraves = self.removed()
@ -178,7 +180,9 @@ class Syncer:
def changes(self) -> dict:
"Bundle up small objects."
d = dict(models=self.getModels(), decks=self.getDecks(), tags=self.getTags())
d: Dict[str, Any] = dict(
models=self.getModels(), decks=self.getDecks(), tags=self.getTags()
)
if self.lnewer:
d["conf"] = self.getConf()
d["crt"] = self.col.crt
@ -328,7 +332,7 @@ from notes where %s"""
def remove(self, graves) -> None:
# pretend to be the server so we don't set usn = -1
self.col.server = True
self.col.server = True # type: ignore
# notes first, so we don't end up with duplicate graves
self.col._remNotes(graves["notes"])
@ -338,7 +342,7 @@ from notes where %s"""
for oid in graves["decks"]:
self.col.decks.rem(oid, childrenToo=False)
self.col.server = False
self.col.server = False # type: ignore
# Models
##########################################################################