From 8372931b9bbb40df21276af791c89e36f7aa60b6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 21 Feb 2021 16:29:55 +1000 Subject: [PATCH] use v2 scheduler+new timezone handling by default for new users - In corner cases, enabling the new timezone handling later can cause reviews to shift forward or back a day, so it's best to have it on by default. - https://github.com/ankidroid/Anki-Android/issues/5805 has not landed in a stable release yet, but will hopefully not be too far off by the time 2.1.41 is released. - Existing users will be unaffected, as the upgrade prompt in the previous commit asks them if they use AnkiDroid. - Users starting on AnkiDroid will be unaffected, as their collections will still be on V1. - The error message AnkiWeb gives when syncing an older AnkiDroid with the new timezone enabled has been updated to direct users to the preferences screen. --- pylib/tests/test_schedv1.py | 1 + rslib/src/config.rs | 5 +++-- rslib/src/storage/sqlite.rs | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index b88d3cf97..4a7e792a3 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -13,6 +13,7 @@ def getEmptyCol(): col = getEmptyColOrig() # only safe in test environment col.set_config("schedVer", 1) + col._loadScheduler() return col diff --git a/rslib/src/config.rs b/rslib/src/config.rs index 925dde90c..f84728b68 100644 --- a/rslib/src/config.rs +++ b/rslib/src/config.rs @@ -18,7 +18,7 @@ use slog::warn; /// new config variables, you do not need to add them here - /// just create an accessor function below with an appropriate /// default on missing/invalid values instead. -pub(crate) fn schema11_config_as_string() -> String { +pub(crate) fn schema11_config_as_string(creation_offset: Option) -> String { let obj = json!({ "activeDecks": [1], "curDeck": 1, @@ -33,7 +33,8 @@ pub(crate) fn schema11_config_as_string() -> String { "sortBackwards": false, "addToCur": true, "dayLearnFirst": false, - "schedVer": 1, + "schedVer": 2, + "creationOffset": creation_offset, }); serde_json::to_string(&obj).unwrap() } diff --git a/rslib/src/storage/sqlite.rs b/rslib/src/storage/sqlite.rs index 6695538de..e1144e49d 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -1,10 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::config::schema11_config_as_string; use crate::err::Result; use crate::err::{AnkiError, DBErrorKind}; use crate::timestamp::{TimestampMillis, TimestampSecs}; +use crate::{config::schema11_config_as_string, sched::cutoff::local_minutes_west_for_stamp}; use crate::{i18n::I18n, sched::cutoff::v1_creation_date, text::without_combining}; use regex::Regex; use rusqlite::{functions::FunctionFlags, params, Connection, NO_PARAMS}; @@ -166,13 +166,18 @@ impl SqliteStorage { db.execute_batch(include_str!("schema11.sql"))?; // start at schema 11, then upgrade below let crt = v1_creation_date(); + let offset = if server { + None + } else { + Some(local_minutes_west_for_stamp(crt)) + }; db.execute( "update col set crt=?, scm=?, ver=?, conf=?", params![ crt, TimestampMillis::now(), SCHEMA_STARTING_VERSION, - &schema11_config_as_string() + &schema11_config_as_string(offset) ], )?; }