diff --git a/proto/backend.proto b/proto/backend.proto index 6b918f447..0ecd55226 100644 --- a/proto/backend.proto +++ b/proto/backend.proto @@ -94,6 +94,7 @@ message BackendInput { AfterNoteUpdatesIn after_note_updates = 80; AddNoteTagsIn add_note_tags = 81; UpdateNoteTagsIn update_note_tags = 82; + int32 set_local_minutes_west = 83; } } @@ -167,6 +168,7 @@ message BackendOutput { Empty after_note_updates = 80; uint32 add_note_tags = 81; uint32 update_note_tags = 82; + Empty set_local_minutes_west = 83; BackendError error = 2047; } diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 869f803a0..6a9b96adf 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -41,7 +41,6 @@ class _Collection: crt: int mod: int scm: int - dty: bool # no longer used _usn: int ls: int _undo: List[Any] @@ -50,7 +49,7 @@ class _Collection: self, db: DBProxy, backend: RustBackend, - server: Optional["anki.storage.ServerData"] = None, + server: bool = False, log: bool = False, ) -> None: self.backend = backend @@ -62,7 +61,7 @@ class _Collection: self.server = server self._lastSave = time.time() self.clearUndo() - self.media = MediaManager(self, server is not None) + self.media = MediaManager(self, server) self.models = ModelManager(self) self.decks = DeckManager(self) self.tags = TagManager(self) @@ -133,16 +132,9 @@ class _Collection: ########################################################################## def load(self) -> None: - ( - self.crt, - self.mod, - self.scm, - self.dty, # no longer used - self._usn, - self.ls, - ) = self.db.first( + (self.crt, self.mod, self.scm, self._usn, self.ls,) = self.db.first( """ -select crt, mod, scm, dty, usn, ls from col""" +select crt, mod, scm, usn, ls from col""" ) def setMod(self) -> None: @@ -157,11 +149,10 @@ is only necessary if you modify properties of this object.""" self.mod = intTime(1000) if mod is None else mod self.db.execute( """update col set -crt=?, mod=?, scm=?, dty=?, usn=?, ls=?""", +crt=?, mod=?, scm=?, usn=?, ls=?""", self.crt, self.mod, self.scm, - self.dty, self._usn, self.ls, ) diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index e4986c417..a57e750c6 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -808,6 +808,9 @@ class RustBackend: ) ).update_note_tags + def set_local_minutes_west(self, mins: int) -> None: + self._run_command(pb.BackendInput(set_local_minutes_west=mins)) + def translate_string_in( key: TR, **kwargs: Union[str, int, float] diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index fbf0d4b23..ad209b88c 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -1390,11 +1390,6 @@ where id = ? def _current_timezone_offset(self) -> Optional[int]: if self.col.server: - mins = self.col.server.minutes_west - if mins is not None: - return mins - # older Anki versions stored the local offset in - # the config return self.col.conf.get("localOffset", 0) else: return None diff --git a/pylib/anki/storage.py b/pylib/anki/storage.py index daa697f9c..1ab88f955 100644 --- a/pylib/anki/storage.py +++ b/pylib/anki/storage.py @@ -3,7 +3,6 @@ import os import weakref -from dataclasses import dataclass from typing import Optional from anki.collection import _Collection @@ -12,21 +11,16 @@ from anki.media import media_paths_from_col_path from anki.rsbackend import RustBackend -@dataclass -class ServerData: - minutes_west: Optional[int] = None - - def Collection( path: str, backend: Optional[RustBackend] = None, - server: Optional[ServerData] = None, + server: bool = False, log: bool = False, ) -> _Collection: "Open a new or existing collection. Path must be unicode." assert path.endswith(".anki2") if backend is None: - backend = RustBackend(server=server is not None) + backend = RustBackend(server=server) (media_dir, media_db) = media_paths_from_col_path(path) log_path = "" diff --git a/pylib/anki/sync.py b/pylib/anki/sync.py index eb171624e..7299583c1 100644 --- a/pylib/anki/sync.py +++ b/pylib/anki/sync.py @@ -330,7 +330,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 # type: ignore + self.col.server = True # notes first, so we don't end up with duplicate graves self.col._remNotes(graves["notes"]) @@ -340,7 +340,7 @@ from notes where %s""" for oid in graves["decks"]: self.col.decks.rem(oid, childrenToo=False) - self.col.server = False # type: ignore + self.col.server = False # Models ########################################################################## diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 8caac1ad1..06cfaaacf 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -366,6 +366,10 @@ impl Backend { } Value::AddNoteTags(input) => OValue::AddNoteTags(self.add_note_tags(input)?), Value::UpdateNoteTags(input) => OValue::UpdateNoteTags(self.update_note_tags(input)?), + Value::SetLocalMinutesWest(mins) => OValue::SetLocalMinutesWest({ + self.set_local_mins_west(mins)?; + pb::Empty {} + }), }) } @@ -1119,6 +1123,10 @@ impl Backend { .map(|n| n as u32) }) } + + fn set_local_mins_west(&self, mins: i32) -> Result<()> { + self.with_col(|col| col.transact(None, |col| col.set_local_mins_west(mins))) + } } fn to_nids(ids: Vec) -> Vec { diff --git a/rslib/src/config.rs b/rslib/src/config.rs index 94ce3096a..8bf455abf 100644 --- a/rslib/src/config.rs +++ b/rslib/src/config.rs @@ -134,6 +134,10 @@ impl Collection { self.get_config_optional(ConfigKey::LocalOffset) } + pub(crate) fn set_local_mins_west(&self, mins: i32) -> Result<()> { + self.set_config(ConfigKey::LocalOffset, &mins) + } + pub(crate) fn get_rollover(&self) -> Option { self.get_config_optional(ConfigKey::Rollover) }