From d878de54c0502bb3f524b2c1d5f88e9d558a9fbe Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 6 May 2021 19:07:31 +1000 Subject: [PATCH] default to the v2 scheduler in new collections ported from 53d9433d94d485af14a606ca9dcf0cd2fa5d54df --- pylib/tests/test_schedv1.py | 1 + rslib/src/config/schema11.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 9ce6945ee..92a402b5f 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -15,6 +15,7 @@ def getEmptyCol() -> Collection: col = getEmptyColOrig() # only safe in test environment col.set_config("schedVer", 1) + col._loadScheduler() return col diff --git a/rslib/src/config/schema11.rs b/rslib/src/config/schema11.rs index e210a5d12..90eac637e 100644 --- a/rslib/src/config/schema11.rs +++ b/rslib/src/config/schema11.rs @@ -7,7 +7,7 @@ use serde_json::json; /// 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, @@ -22,7 +22,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 ff1331718..22418b22f 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -12,7 +12,7 @@ use crate::{ config::schema11::schema11_config_as_string, error::{AnkiError, DbErrorKind, Result}, i18n::I18n, - scheduler::timing::v1_creation_date, + scheduler::timing::{local_minutes_west_for_stamp, v1_creation_date}, text::without_combining, timestamp::TimestampMillis, }; @@ -168,13 +168,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) ], )?; }