mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
add indexes to graves table to speed up undo
This commit is contained in:
parent
44dc3f494c
commit
28994458e9
4 changed files with 44 additions and 5 deletions
|
@ -72,7 +72,6 @@ impl SqliteStorage {
|
|||
Ok(graves)
|
||||
}
|
||||
|
||||
// fixme: graves is missing an index
|
||||
pub(crate) fn update_pending_grave_usns(&self, new_usn: Usn) -> Result<()> {
|
||||
self.db
|
||||
.prepare("update graves set usn=? where usn=-1")?
|
||||
|
|
|
@ -6,7 +6,7 @@ pub(super) const SCHEMA_MIN_VERSION: u8 = 11;
|
|||
/// The version new files are initially created with.
|
||||
pub(super) const SCHEMA_STARTING_VERSION: u8 = 11;
|
||||
/// The maximum schema version we can open.
|
||||
pub(super) const SCHEMA_MAX_VERSION: u8 = 17;
|
||||
pub(super) const SCHEMA_MAX_VERSION: u8 = 18;
|
||||
|
||||
use super::SqliteStorage;
|
||||
use crate::err::Result;
|
||||
|
@ -35,9 +35,14 @@ impl SqliteStorage {
|
|||
self.upgrade_tags_to_schema17()?;
|
||||
self.db.execute_batch("update col set ver = 17")?;
|
||||
}
|
||||
// fixme: on the next schema upgrade, change _collapsed to _expanded
|
||||
// in DeckCommon and invert existing values, so that we can avoid
|
||||
// serializing the values in the default case, and use
|
||||
if ver < 18 {
|
||||
self.db
|
||||
.execute_batch(include_str!("schema18_upgrade.sql"))?;
|
||||
}
|
||||
|
||||
// in some future schema upgrade, we may want to change
|
||||
// _collapsed to _expanded in DeckCommon and invert existing values, so
|
||||
// that we can avoid serializing the values in the default case, and use
|
||||
// DeckCommon::default() in new_normal() and new_filtered()
|
||||
|
||||
Ok(())
|
||||
|
@ -46,6 +51,8 @@ impl SqliteStorage {
|
|||
pub(super) fn downgrade_to_schema_11(&self) -> Result<()> {
|
||||
self.begin_trx()?;
|
||||
|
||||
self.db
|
||||
.execute_batch(include_str!("schema18_downgrade.sql"))?;
|
||||
self.downgrade_deck_conf_from_schema16()?;
|
||||
self.downgrade_decks_from_schema15()?;
|
||||
self.downgrade_notetypes_from_schema15()?;
|
||||
|
|
15
rslib/src/storage/upgrades/schema18_downgrade.sql
Normal file
15
rslib/src/storage/upgrades/schema18_downgrade.sql
Normal file
|
@ -0,0 +1,15 @@
|
|||
ALTER TABLE graves
|
||||
RENAME TO graves_old;
|
||||
CREATE TABLE graves (
|
||||
usn integer NOT NULL,
|
||||
oid integer NOT NULL,
|
||||
type integer NOT NULL
|
||||
);
|
||||
INSERT INTO graves (usn, oid, type)
|
||||
SELECT usn,
|
||||
oid,
|
||||
type
|
||||
FROM graves_old;
|
||||
DROP TABLE graves_old;
|
||||
UPDATE col
|
||||
SET ver = 17;
|
18
rslib/src/storage/upgrades/schema18_upgrade.sql
Normal file
18
rslib/src/storage/upgrades/schema18_upgrade.sql
Normal file
|
@ -0,0 +1,18 @@
|
|||
ALTER TABLE graves
|
||||
RENAME TO graves_old;
|
||||
CREATE TABLE graves (
|
||||
oid integer NOT NULL,
|
||||
type integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
PRIMARY KEY (oid, type)
|
||||
) WITHOUT ROWID;
|
||||
INSERT
|
||||
OR IGNORE INTO graves (oid, type, usn)
|
||||
SELECT oid,
|
||||
type,
|
||||
usn
|
||||
FROM graves_old;
|
||||
DROP TABLE graves_old;
|
||||
CREATE INDEX idx_graves_pending ON graves (usn);
|
||||
UPDATE col
|
||||
SET ver = 18;
|
Loading…
Reference in a new issue