Merge branch 'master' into backend-filters
Adapt new formatting.
This commit is contained in:
commit
f83553c82a
3
defs.bzl
3
defs.bzl
@ -4,6 +4,7 @@ load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
|
||||
load("@net_ankiweb_anki//cargo:crates.bzl", "raze_fetch_remote_crates")
|
||||
load(":python.bzl", "setup_local_python")
|
||||
load(":protobuf.bzl", "setup_protobuf_binary")
|
||||
load("//rslib:clang_format.bzl", "setup_clang_format")
|
||||
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
|
||||
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
|
||||
load("@build_bazel_rules_svelte//:defs.bzl", "rules_svelte_dependencies")
|
||||
@ -28,6 +29,8 @@ def setup_deps():
|
||||
|
||||
setup_protobuf_binary(name = "com_google_protobuf")
|
||||
|
||||
setup_clang_format(name = "clang_format")
|
||||
|
||||
native.register_toolchains("@python//:python3_toolchain")
|
||||
|
||||
pip_import(
|
||||
|
@ -115,6 +115,8 @@ in the relevant package:
|
||||
|
||||
```
|
||||
bazel run //rslib:format
|
||||
bazel run //rslib:sql_format
|
||||
bazel run //rslib:proto_format
|
||||
bazel run //pylib:format
|
||||
bazel run //qt:format
|
||||
bazel run //ts:format
|
||||
|
@ -136,7 +136,6 @@ class DataModel(QAbstractTableModel):
|
||||
if role == Qt.FontRole:
|
||||
if self.activeCols[index.column()] not in ("question", "answer", "noteFld"):
|
||||
return
|
||||
row = index.row()
|
||||
c = self.getCard(index)
|
||||
t = c.template()
|
||||
if not t.get("bfont"):
|
||||
@ -298,7 +297,6 @@ class DataModel(QAbstractTableModel):
|
||||
return "%Y-%m-%d"
|
||||
|
||||
def columnData(self, index):
|
||||
row = index.row()
|
||||
col = index.column()
|
||||
type = self.columnType(col)
|
||||
c = self.getCard(index)
|
||||
@ -393,7 +391,6 @@ class DataModel(QAbstractTableModel):
|
||||
if type != "noteFld":
|
||||
return False
|
||||
|
||||
row = index.row()
|
||||
c = self.getCard(index)
|
||||
nt = c.note().model()
|
||||
return nt["flds"][self.col.models.sortIdx(nt)]["rtl"]
|
||||
@ -2073,7 +2070,7 @@ where id in %s"""
|
||||
self.model.beginReset()
|
||||
self.mw.checkpoint(tr(TR.BROWSING_TAG_DUPLICATES))
|
||||
nids = set()
|
||||
for s, nidlist in res:
|
||||
for _, nidlist in res:
|
||||
nids.update(nidlist)
|
||||
self.col.tags.bulkAdd(list(nids), tr(TR.BROWSING_DUPLICATE))
|
||||
self.mw.progress.finish()
|
||||
|
@ -270,7 +270,6 @@ class AnkiQt(QMainWindow):
|
||||
# called on .clear()
|
||||
return
|
||||
name = self.pm.profiles()[n]
|
||||
f = self.profileForm
|
||||
self.pm.load(name)
|
||||
|
||||
def openProfile(self):
|
||||
|
@ -71,7 +71,6 @@ class TagLimit(QDialog):
|
||||
|
||||
def accept(self):
|
||||
self.hide()
|
||||
n = 0
|
||||
# gather yes/no tags
|
||||
yes = []
|
||||
no = []
|
||||
|
@ -201,16 +201,11 @@ class ButtonedDialog(QMessageBox):
|
||||
self.help = help
|
||||
self.setIcon(QMessageBox.Warning)
|
||||
self.setText(text)
|
||||
# v = QVBoxLayout()
|
||||
# v.addWidget(QLabel(text))
|
||||
# box = QDialogButtonBox()
|
||||
# v.addWidget(box)
|
||||
for b in buttons:
|
||||
self._buttons.append(self.addButton(b, QMessageBox.AcceptRole))
|
||||
if help:
|
||||
self.addButton(tr(TR.ACTIONS_HELP), QMessageBox.HelpRole)
|
||||
buttons.append(tr(TR.ACTIONS_HELP))
|
||||
# self.setLayout(v)
|
||||
|
||||
def run(self):
|
||||
self.exec_()
|
||||
|
@ -22,7 +22,7 @@ if __name__ == "__main__":
|
||||
"black",
|
||||
"-t",
|
||||
"py38",
|
||||
"--exclude=aqt/forms|colors",
|
||||
"--exclude=aqt/forms|colors|_gen",
|
||||
"aqt",
|
||||
"tests",
|
||||
"tools",
|
||||
|
@ -2,6 +2,8 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
|
||||
load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
|
||||
load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
|
||||
load(":clang_format.bzl", "proto_format")
|
||||
load("//ts:sql_format.bzl", "sql_format")
|
||||
|
||||
# Build script
|
||||
#######################
|
||||
@ -143,6 +145,16 @@ rustfmt_fix(
|
||||
]),
|
||||
)
|
||||
|
||||
sql_format(
|
||||
name = "sql_format",
|
||||
srcs = glob(["**/*.sql"]),
|
||||
)
|
||||
|
||||
proto_format(
|
||||
name = "proto_format",
|
||||
srcs = ["backend.proto"],
|
||||
)
|
||||
|
||||
# fluent.proto generation
|
||||
###########################
|
||||
# This separate step is required to make the file available to downstream consumers.
|
||||
|
1339
rslib/backend.proto
1339
rslib/backend.proto
File diff suppressed because it is too large
Load Diff
73
rslib/clang_format.bzl
Normal file
73
rslib/clang_format.bzl
Normal file
@ -0,0 +1,73 @@
|
||||
"""
|
||||
Exposes a clang-format binary for formatting protobuf.
|
||||
"""
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
||||
load("@rules_python//python:defs.bzl", "py_test")
|
||||
|
||||
def _impl(rctx):
|
||||
rctx.file("BUILD.bazel", """
|
||||
alias(
|
||||
name = "clang_format",
|
||||
actual = select({
|
||||
"@net_ankiweb_anki//platforms:windows_x86_64": "@clang_format_windows_x86_64//:clang-format.exe",
|
||||
"@net_ankiweb_anki//platforms:macos_x86_64": "@clang_format_macos_x86_64//:clang-format",
|
||||
"@net_ankiweb_anki//platforms:linux_x86_64": "@clang_format_linux_x86_64//:clang-format",
|
||||
}),
|
||||
visibility = ["//visibility:public"]
|
||||
)
|
||||
""")
|
||||
|
||||
_setup_clang_format = repository_rule(
|
||||
attrs = {},
|
||||
local = True,
|
||||
implementation = _impl,
|
||||
)
|
||||
|
||||
def setup_clang_format(name):
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "clang_format_macos_x86_64",
|
||||
build_file_content = """exports_files(["clang-format"])""",
|
||||
sha256 = "238be68d9478163a945754f06a213483473044f5a004c4125d3d9d8d3556466e",
|
||||
urls = [
|
||||
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_macos_x86_64.zip",
|
||||
],
|
||||
)
|
||||
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "clang_format_linux_x86_64",
|
||||
build_file_content = """exports_files(["clang-format"])""",
|
||||
sha256 = "64060bc4dbca30d0d96aab9344e2783008b16e1cae019a2532f1126ca5ec5449",
|
||||
urls = [
|
||||
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_linux_x86_64.zip",
|
||||
],
|
||||
)
|
||||
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "clang_format_windows_x86_64",
|
||||
build_file_content = """exports_files(["clang-format.exe"])""",
|
||||
sha256 = "7d9f6915e3f0fb72407830f0fc37141308d2e6915daba72987a52f309fbeaccc",
|
||||
urls = [
|
||||
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_windows_x86_64.zip",
|
||||
],
|
||||
)
|
||||
|
||||
if not native.existing_rule(name):
|
||||
_setup_clang_format(
|
||||
name = name,
|
||||
)
|
||||
|
||||
def proto_format(name, srcs, **kwargs):
|
||||
py_test(
|
||||
name = name,
|
||||
srcs = [
|
||||
"proto_format.py",
|
||||
],
|
||||
data = ["@clang_format//:clang_format"] + srcs,
|
||||
args = ["$(location @clang_format//:clang_format)"] + [native.package_name() + "/" + f for f in srcs],
|
||||
**kwargs
|
||||
)
|
36
rslib/proto_format.py
Executable file
36
rslib/proto_format.py
Executable file
@ -0,0 +1,36 @@
|
||||
import sys, subprocess, os, difflib
|
||||
|
||||
clang_format = sys.argv[1]
|
||||
workspace = os.environ.get("BUILD_WORKSPACE_DIRECTORY", "")
|
||||
want_fix = bool(workspace)
|
||||
|
||||
found_bad = False
|
||||
for path in sys.argv[2:]:
|
||||
with open(path) as file:
|
||||
orig = file.read()
|
||||
new = subprocess.check_output(
|
||||
# [clang_format, "--style={'BasedOnStyle': 'google', 'IndentWidth': 4}", path]
|
||||
[clang_format, "--style=google", path]
|
||||
).decode("utf-8")
|
||||
if orig != new:
|
||||
if want_fix:
|
||||
with open(os.path.join(workspace, path), "w") as file:
|
||||
file.write(new)
|
||||
print("fixed", path)
|
||||
else:
|
||||
print(f"Bad formatting in {path}")
|
||||
print(
|
||||
"\n".join(
|
||||
difflib.unified_diff(
|
||||
orig.splitlines(),
|
||||
new.splitlines(),
|
||||
fromfile="bad",
|
||||
tofile="good",
|
||||
lineterm="",
|
||||
)
|
||||
)
|
||||
)
|
||||
found_bad = True
|
||||
|
||||
if found_bad:
|
||||
sys.exit(1)
|
@ -1,10 +1,13 @@
|
||||
create table media (
|
||||
fname text not null primary key,
|
||||
csum text, -- null indicates deleted file
|
||||
mtime int not null, -- zero if deleted
|
||||
dirty int not null
|
||||
CREATE TABLE media (
|
||||
fname text NOT NULL PRIMARY KEY,
|
||||
-- null indicates deleted file
|
||||
csum text,
|
||||
-- zero if deleted
|
||||
mtime int NOT NULL,
|
||||
dirty int NOT NULL
|
||||
) without rowid;
|
||||
|
||||
create index idx_media_dirty on media (dirty) where dirty=1;
|
||||
|
||||
create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||
CREATE INDEX idx_media_dirty ON media (dirty)
|
||||
WHERE dirty = 1;
|
||||
CREATE TABLE meta (dirMod int, lastUsn int);
|
||||
INSERT INTO meta
|
||||
VALUES (0, 0);
|
@ -4,7 +4,6 @@
|
||||
use crate::{
|
||||
card::{Card, CardID, CardQueue, CardType},
|
||||
collection::Collection,
|
||||
deckconf::INITIAL_EASE_FACTOR_THOUSANDS,
|
||||
decks::DeckID,
|
||||
err::Result,
|
||||
notes::NoteID,
|
||||
@ -21,11 +20,7 @@ impl Card {
|
||||
self.ctype = CardType::New;
|
||||
self.queue = CardQueue::New;
|
||||
self.interval = 0;
|
||||
if self.ease_factor == 0 {
|
||||
// unlike the old Python code, we leave the ease factor alone
|
||||
// if it's already set
|
||||
self.ease_factor = INITIAL_EASE_FACTOR_THOUSANDS;
|
||||
}
|
||||
self.ease_factor = 0;
|
||||
}
|
||||
|
||||
/// If the card is new, change its position.
|
||||
|
@ -1,11 +1,9 @@
|
||||
drop table if exists sort_order;
|
||||
create temporary table sort_order (
|
||||
pos integer primary key,
|
||||
did integer not null unique
|
||||
DROP TABLE IF EXISTS sort_order;
|
||||
CREATE TEMPORARY TABLE sort_order (
|
||||
pos integer PRIMARY KEY,
|
||||
did integer NOT NULL UNIQUE
|
||||
);
|
||||
insert into sort_order (did)
|
||||
select
|
||||
id
|
||||
from decks
|
||||
order by
|
||||
name;
|
||||
INSERT INTO sort_order (did)
|
||||
SELECT id
|
||||
FROM decks
|
||||
ORDER BY name;
|
@ -1,11 +1,9 @@
|
||||
drop table if exists sort_order;
|
||||
create temporary table sort_order (
|
||||
pos integer primary key,
|
||||
ntid integer not null unique
|
||||
DROP TABLE IF EXISTS sort_order;
|
||||
CREATE TEMPORARY TABLE sort_order (
|
||||
pos integer PRIMARY KEY,
|
||||
ntid integer NOT NULL UNIQUE
|
||||
);
|
||||
insert into sort_order (ntid)
|
||||
select
|
||||
id
|
||||
from notetypes
|
||||
order by
|
||||
name;
|
||||
INSERT INTO sort_order (ntid)
|
||||
SELECT id
|
||||
FROM notetypes
|
||||
ORDER BY name;
|
@ -1,14 +1,12 @@
|
||||
drop table if exists sort_order;
|
||||
create temporary table sort_order (
|
||||
pos integer primary key,
|
||||
ntid integer not null,
|
||||
ord integer not null,
|
||||
unique(ntid, ord)
|
||||
DROP TABLE IF EXISTS sort_order;
|
||||
CREATE TEMPORARY TABLE sort_order (
|
||||
pos integer PRIMARY KEY,
|
||||
ntid integer NOT NULL,
|
||||
ord integer NOT NULL,
|
||||
UNIQUE(ntid, ord)
|
||||
);
|
||||
insert into sort_order (ntid, ord)
|
||||
select
|
||||
ntid,
|
||||
INSERT INTO sort_order (ntid, ord)
|
||||
SELECT ntid,
|
||||
ord
|
||||
from templates
|
||||
order by
|
||||
name
|
||||
FROM templates
|
||||
ORDER BY name
|
@ -1,4 +1,4 @@
|
||||
insert into cards (
|
||||
INSERT INTO cards (
|
||||
id,
|
||||
nid,
|
||||
did,
|
||||
@ -18,21 +18,18 @@ insert into cards (
|
||||
flags,
|
||||
data
|
||||
)
|
||||
values
|
||||
(
|
||||
VALUES (
|
||||
(
|
||||
case
|
||||
when ?1 in (
|
||||
select
|
||||
id
|
||||
from cards
|
||||
) then (
|
||||
select
|
||||
max(id) + 1
|
||||
from cards
|
||||
CASE
|
||||
WHEN ?1 IN (
|
||||
SELECT id
|
||||
FROM cards
|
||||
) THEN (
|
||||
SELECT max(id) + 1
|
||||
FROM cards
|
||||
)
|
||||
else ?1
|
||||
end
|
||||
ELSE ?1
|
||||
END
|
||||
),
|
||||
?,
|
||||
?,
|
||||
|
@ -1,5 +1,5 @@
|
||||
insert
|
||||
or replace into cards (
|
||||
INSERT
|
||||
OR REPLACE INTO cards (
|
||||
id,
|
||||
nid,
|
||||
did,
|
||||
@ -19,8 +19,7 @@ insert
|
||||
flags,
|
||||
data
|
||||
)
|
||||
values
|
||||
(
|
||||
VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
|
@ -1,5 +1,5 @@
|
||||
insert into search_cids
|
||||
select id
|
||||
from cards
|
||||
where due >= ?
|
||||
and type = ?
|
||||
INSERT INTO search_cids
|
||||
SELECT id
|
||||
FROM cards
|
||||
WHERE due >= ?
|
||||
AND type = ?
|
@ -1,28 +1,28 @@
|
||||
select coalesce(
|
||||
sum(
|
||||
queue in (:review_queue, :day_learn_queue)
|
||||
and due <= :today
|
||||
),
|
||||
0
|
||||
) as review_count,
|
||||
coalesce(sum(queue = :new_queue), 0) as new_count,
|
||||
coalesce(sum(queue = :sched_buried_queue), 0) as sched_buried,
|
||||
coalesce(sum(queue = :user_buried_queue), 0) as user_buried,
|
||||
coalesce(sum(queue = :learn_queue), 0) as learn_count,
|
||||
max(
|
||||
0,
|
||||
coalesce(
|
||||
min(
|
||||
case
|
||||
when queue = :learn_queue then due
|
||||
else null
|
||||
end
|
||||
),
|
||||
0
|
||||
)
|
||||
) as first_learn_due
|
||||
from cards
|
||||
where did in (
|
||||
select id
|
||||
from active_decks
|
||||
)
|
||||
SELECT coalesce(
|
||||
sum(
|
||||
queue IN (:review_queue, :day_learn_queue)
|
||||
AND due <= :today
|
||||
),
|
||||
0
|
||||
) AS review_count,
|
||||
coalesce(sum(queue = :new_queue), 0) AS new_count,
|
||||
coalesce(sum(queue = :sched_buried_queue), 0) AS sched_buried,
|
||||
coalesce(sum(queue = :user_buried_queue), 0) AS user_buried,
|
||||
coalesce(sum(queue = :learn_queue), 0) AS learn_count,
|
||||
max(
|
||||
0,
|
||||
coalesce(
|
||||
min(
|
||||
CASE
|
||||
WHEN queue = :learn_queue THEN due
|
||||
ELSE NULL
|
||||
END
|
||||
),
|
||||
0
|
||||
)
|
||||
) AS first_learn_due
|
||||
FROM cards
|
||||
WHERE did IN (
|
||||
SELECT id
|
||||
FROM active_decks
|
||||
)
|
@ -1,20 +1,18 @@
|
||||
update cards
|
||||
set
|
||||
due = (
|
||||
case
|
||||
when type = 0
|
||||
and queue != 4 then 1000000 + due % 1000000
|
||||
else due
|
||||
end
|
||||
UPDATE cards
|
||||
SET due = (
|
||||
CASE
|
||||
WHEN type = 0
|
||||
AND queue != 4 THEN 1000000 + due % 1000000
|
||||
ELSE due
|
||||
END
|
||||
),
|
||||
mod = ?1,
|
||||
usn = ?2
|
||||
where
|
||||
due != (
|
||||
case
|
||||
when type = 0
|
||||
and queue != 4 then 1000000 + due % 1000000
|
||||
else due
|
||||
end
|
||||
WHERE due != (
|
||||
CASE
|
||||
WHEN type = 0
|
||||
AND queue != 4 THEN 1000000 + due % 1000000
|
||||
ELSE due
|
||||
END
|
||||
)
|
||||
and due >= 1000000;
|
||||
AND due >= 1000000;
|
@ -1,19 +1,17 @@
|
||||
update cards
|
||||
set
|
||||
due = (
|
||||
case
|
||||
when queue = 2
|
||||
and due > 100000 then ?1
|
||||
else min(max(round(due), -2147483648), 2147483647)
|
||||
end
|
||||
UPDATE cards
|
||||
SET due = (
|
||||
CASE
|
||||
WHEN queue = 2
|
||||
AND due > 100000 THEN ?1
|
||||
ELSE min(max(round(due), -2147483648), 2147483647)
|
||||
END
|
||||
),
|
||||
mod = ?2,
|
||||
usn = ?3
|
||||
where
|
||||
due != (
|
||||
case
|
||||
when queue = 2
|
||||
and due > 100000 then ?1
|
||||
else min(max(round(due), -2147483648), 2147483647)
|
||||
end
|
||||
WHERE due != (
|
||||
CASE
|
||||
WHEN queue = 2
|
||||
AND due > 100000 THEN ?1
|
||||
ELSE min(max(round(due), -2147483648), 2147483647)
|
||||
END
|
||||
);
|
@ -1,7 +1,5 @@
|
||||
update cards
|
||||
set
|
||||
ivl = min(max(round(ivl), 0), 2147483647),
|
||||
UPDATE cards
|
||||
SET ivl = min(max(round(ivl), 0), 2147483647),
|
||||
mod = ?1,
|
||||
usn = ?2
|
||||
where
|
||||
ivl != min(max(round(ivl), 0), 2147483647)
|
||||
WHERE ivl != min(max(round(ivl), 0), 2147483647)
|
@ -1,10 +1,10 @@
|
||||
update cards
|
||||
set factor = 2500,
|
||||
usn = ?,
|
||||
mod = ?
|
||||
where factor != 0
|
||||
and factor <= 2000
|
||||
and (
|
||||
did in DECK_IDS
|
||||
or odid in DECK_IDS
|
||||
)
|
||||
UPDATE cards
|
||||
SET factor = 2500,
|
||||
usn = ?,
|
||||
mod = ?
|
||||
WHERE factor != 0
|
||||
AND factor <= 2000
|
||||
AND (
|
||||
did IN DECK_IDS
|
||||
OR odid IN DECK_IDS
|
||||
)
|
@ -1,27 +1,25 @@
|
||||
update cards
|
||||
set
|
||||
odue = (
|
||||
case
|
||||
when odue > 0
|
||||
and (
|
||||
UPDATE cards
|
||||
SET odue = (
|
||||
CASE
|
||||
WHEN odue > 0
|
||||
AND (
|
||||
type = 1
|
||||
or queue = 2
|
||||
OR queue = 2
|
||||
)
|
||||
and not odid then 0
|
||||
else min(max(round(odue), -2147483648), 2147483647)
|
||||
end
|
||||
AND NOT odid THEN 0
|
||||
ELSE min(max(round(odue), -2147483648), 2147483647)
|
||||
END
|
||||
),
|
||||
mod = ?1,
|
||||
usn = ?2
|
||||
where
|
||||
odue != (
|
||||
case
|
||||
when odue > 0
|
||||
and (
|
||||
WHERE odue != (
|
||||
CASE
|
||||
WHEN odue > 0
|
||||
AND (
|
||||
type = 1
|
||||
or queue = 2
|
||||
OR queue = 2
|
||||
)
|
||||
and not odid then 0
|
||||
else min(max(round(odue), -2147483648), 2147483647)
|
||||
end
|
||||
AND NOT odid THEN 0
|
||||
ELSE min(max(round(odue), -2147483648), 2147483647)
|
||||
END
|
||||
);
|
@ -1,14 +1,13 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
nid,
|
||||
did,
|
||||
ord,
|
||||
cast(mod as integer),
|
||||
cast(mod AS integer),
|
||||
usn,
|
||||
type,
|
||||
queue,
|
||||
due,
|
||||
cast(ivl as integer),
|
||||
cast(ivl AS integer),
|
||||
factor,
|
||||
reps,
|
||||
lapses,
|
||||
@ -17,4 +16,4 @@ select
|
||||
odid,
|
||||
flags,
|
||||
data
|
||||
from cards
|
||||
FROM cards
|
@ -1,2 +1,2 @@
|
||||
drop table if exists search_cids;
|
||||
create temporary table search_cids (cid integer primary key not null);
|
||||
DROP TABLE IF EXISTS search_cids;
|
||||
CREATE TEMPORARY TABLE search_cids (cid integer PRIMARY KEY NOT NULL);
|
@ -1,2 +1,2 @@
|
||||
drop table if exists search_cids;
|
||||
create temporary table search_cids (cid integer not null);
|
||||
DROP TABLE IF EXISTS search_cids;
|
||||
CREATE TEMPORARY TABLE search_cids (cid integer NOT NULL);
|
@ -1,6 +1,5 @@
|
||||
update cards
|
||||
set
|
||||
nid = ?,
|
||||
UPDATE cards
|
||||
SET nid = ?,
|
||||
did = ?,
|
||||
ord = ?,
|
||||
mod = ?,
|
||||
@ -17,5 +16,4 @@ set
|
||||
odid = ?,
|
||||
flags = ?,
|
||||
data = ?
|
||||
where
|
||||
id = ?
|
||||
WHERE id = ?
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or replace into config (key, usn, mtime_secs, val)
|
||||
values
|
||||
(?, ?, ?, ?)
|
||||
INSERT
|
||||
OR REPLACE INTO config (KEY, usn, mtime_secs, val)
|
||||
VALUES (?, ?, ?, ?)
|
@ -1,5 +1,3 @@
|
||||
select
|
||||
val
|
||||
from config
|
||||
where
|
||||
key = ?
|
||||
SELECT val
|
||||
FROM config
|
||||
WHERE KEY = ?
|
@ -1,13 +1,10 @@
|
||||
select
|
||||
case
|
||||
when ?1 in (
|
||||
select
|
||||
id
|
||||
from decks
|
||||
) then (
|
||||
select
|
||||
max(id) + 1
|
||||
from decks
|
||||
SELECT CASE
|
||||
WHEN ?1 IN (
|
||||
SELECT id
|
||||
FROM decks
|
||||
) THEN (
|
||||
SELECT max(id) + 1
|
||||
FROM decks
|
||||
)
|
||||
else ?1
|
||||
end;
|
||||
ELSE ?1
|
||||
END;
|
@ -1,9 +1,7 @@
|
||||
select
|
||||
id
|
||||
from cards
|
||||
where
|
||||
did = ?1
|
||||
or (
|
||||
SELECT id
|
||||
FROM cards
|
||||
WHERE did = ?1
|
||||
OR (
|
||||
odid != 0
|
||||
and odid = ?1
|
||||
AND odid = ?1
|
||||
)
|
@ -1,41 +1,41 @@
|
||||
select did,
|
||||
SELECT did,
|
||||
sum(queue = :new_queue),
|
||||
sum(
|
||||
queue = :review_queue
|
||||
and due <= :day_cutoff
|
||||
AND due <= :day_cutoff
|
||||
),
|
||||
-- learning
|
||||
sum(
|
||||
(
|
||||
case
|
||||
CASE
|
||||
:sched_ver
|
||||
when 2 then (
|
||||
WHEN 2 THEN (
|
||||
-- v2 scheduler
|
||||
(
|
||||
queue = :learn_queue
|
||||
and due < :learn_cutoff
|
||||
AND due < :learn_cutoff
|
||||
)
|
||||
or (
|
||||
OR (
|
||||
queue = :daylearn_queue
|
||||
and due <= :day_cutoff
|
||||
AND due <= :day_cutoff
|
||||
)
|
||||
or (
|
||||
OR (
|
||||
queue = :preview_queue
|
||||
and due <= :learn_cutoff
|
||||
AND due <= :learn_cutoff
|
||||
)
|
||||
)
|
||||
else (
|
||||
ELSE (
|
||||
-- v1 scheduler
|
||||
case
|
||||
when queue = :learn_queue
|
||||
and due < :learn_cutoff then left / 1000
|
||||
when queue = :daylearn_queue
|
||||
and due <= :day_cutoff then 1
|
||||
else 0
|
||||
end
|
||||
CASE
|
||||
WHEN queue = :learn_queue
|
||||
AND due < :learn_cutoff THEN left / 1000
|
||||
WHEN queue = :daylearn_queue
|
||||
AND due <= :day_cutoff THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
)
|
||||
end
|
||||
END
|
||||
)
|
||||
)
|
||||
from cards
|
||||
where queue >= 0
|
||||
FROM cards
|
||||
WHERE queue >= 0
|
@ -1,8 +1,7 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
name,
|
||||
mtime_secs,
|
||||
usn,
|
||||
common,
|
||||
kind
|
||||
from decks
|
||||
FROM decks
|
@ -1,9 +1,6 @@
|
||||
select
|
||||
distinct did
|
||||
from cards
|
||||
where
|
||||
did not in (
|
||||
select
|
||||
id
|
||||
from decks
|
||||
SELECT DISTINCT did
|
||||
FROM cards
|
||||
WHERE did NOT IN (
|
||||
SELECT id
|
||||
FROM decks
|
||||
);
|
@ -1,8 +1,8 @@
|
||||
insert into active_decks
|
||||
select id
|
||||
from decks
|
||||
where name = ?
|
||||
or (
|
||||
name >= ?
|
||||
and name < ?
|
||||
)
|
||||
INSERT INTO active_decks
|
||||
SELECT id
|
||||
FROM decks
|
||||
WHERE name = ?
|
||||
OR (
|
||||
name >= ?
|
||||
AND name < ?
|
||||
)
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or replace into decks (id, name, mtime_secs, usn, common, kind)
|
||||
values
|
||||
(?, ?, ?, ?, ?, ?)
|
||||
INSERT
|
||||
OR REPLACE INTO decks (id, name, mtime_secs, usn, common, kind)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
@ -1,19 +1,16 @@
|
||||
insert into deck_config (id, name, mtime_secs, usn, config)
|
||||
values
|
||||
(
|
||||
INSERT INTO deck_config (id, name, mtime_secs, usn, config)
|
||||
VALUES (
|
||||
(
|
||||
case
|
||||
when ?1 in (
|
||||
select
|
||||
id
|
||||
from deck_config
|
||||
) then (
|
||||
select
|
||||
max(id) + 1
|
||||
from deck_config
|
||||
CASE
|
||||
WHEN ?1 IN (
|
||||
SELECT id
|
||||
FROM deck_config
|
||||
) THEN (
|
||||
SELECT max(id) + 1
|
||||
FROM deck_config
|
||||
)
|
||||
else ?1
|
||||
end
|
||||
ELSE ?1
|
||||
END
|
||||
),
|
||||
?,
|
||||
?,
|
||||
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or replace into deck_config (id, name, mtime_secs, usn, config)
|
||||
values
|
||||
(?, ?, ?, ?, ?);
|
||||
INSERT
|
||||
OR REPLACE INTO deck_config (id, name, mtime_secs, usn, config)
|
||||
VALUES (?, ?, ?, ?, ?);
|
@ -1,7 +1,6 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
name,
|
||||
mtime_secs,
|
||||
usn,
|
||||
config
|
||||
from deck_config
|
||||
FROM deck_config
|
@ -1,8 +1,6 @@
|
||||
update deck_config
|
||||
set
|
||||
name = ?,
|
||||
UPDATE deck_config
|
||||
SET name = ?,
|
||||
mtime_secs = ?,
|
||||
usn = ?,
|
||||
config = ?
|
||||
where
|
||||
id = ?;
|
||||
WHERE id = ?;
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or ignore into graves (usn, oid, type)
|
||||
values
|
||||
(?, ?, ?)
|
||||
INSERT
|
||||
OR IGNORE INTO graves (usn, oid, type)
|
||||
VALUES (?, ?, ?)
|
@ -1,4 +1,4 @@
|
||||
insert into notes (
|
||||
INSERT INTO notes (
|
||||
id,
|
||||
guid,
|
||||
mid,
|
||||
@ -11,21 +11,18 @@ insert into notes (
|
||||
flags,
|
||||
data
|
||||
)
|
||||
values
|
||||
(
|
||||
VALUES (
|
||||
(
|
||||
case
|
||||
when ?1 in (
|
||||
select
|
||||
id
|
||||
from notes
|
||||
) then (
|
||||
select
|
||||
max(id) + 1
|
||||
from notes
|
||||
CASE
|
||||
WHEN ?1 IN (
|
||||
SELECT id
|
||||
FROM notes
|
||||
) THEN (
|
||||
SELECT max(id) + 1
|
||||
FROM notes
|
||||
)
|
||||
else ?1
|
||||
end
|
||||
ELSE ?1
|
||||
END
|
||||
),
|
||||
?,
|
||||
?,
|
||||
|
@ -1,5 +1,5 @@
|
||||
insert
|
||||
or replace into notes (
|
||||
INSERT
|
||||
OR REPLACE INTO notes (
|
||||
id,
|
||||
guid,
|
||||
mid,
|
||||
@ -12,8 +12,7 @@ insert
|
||||
flags,
|
||||
data
|
||||
)
|
||||
values
|
||||
(
|
||||
VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
|
@ -1,9 +1,8 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
guid,
|
||||
mid,
|
||||
mod,
|
||||
usn,
|
||||
tags,
|
||||
flds
|
||||
from notes
|
||||
FROM notes
|
@ -1,5 +1,3 @@
|
||||
select
|
||||
count(id) = 0
|
||||
from cards
|
||||
where
|
||||
nid = ?;
|
||||
SELECT COUNT(id) = 0
|
||||
FROM cards
|
||||
WHERE nid = ?;
|
@ -1,6 +1,5 @@
|
||||
update notes
|
||||
set
|
||||
guid = ?,
|
||||
UPDATE notes
|
||||
SET guid = ?,
|
||||
mid = ?,
|
||||
mod = ?,
|
||||
usn = ?,
|
||||
@ -8,5 +7,4 @@ set
|
||||
flds = ?,
|
||||
sfld = ?,
|
||||
csum = ?
|
||||
where
|
||||
id = ?
|
||||
WHERE id = ?
|
@ -1,19 +1,16 @@
|
||||
insert into notetypes (id, name, mtime_secs, usn, config)
|
||||
values
|
||||
(
|
||||
INSERT INTO notetypes (id, name, mtime_secs, usn, config)
|
||||
VALUES (
|
||||
(
|
||||
case
|
||||
when ?1 in (
|
||||
select
|
||||
id
|
||||
from notetypes
|
||||
) then (
|
||||
select
|
||||
max(id) + 1
|
||||
from notetypes
|
||||
CASE
|
||||
WHEN ?1 IN (
|
||||
SELECT id
|
||||
FROM notetypes
|
||||
) THEN (
|
||||
SELECT max(id) + 1
|
||||
FROM notetypes
|
||||
)
|
||||
else ?1
|
||||
end
|
||||
ELSE ?1
|
||||
END
|
||||
),
|
||||
?,
|
||||
?,
|
||||
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or replace into notetypes (id, name, mtime_secs, usn, config)
|
||||
values
|
||||
(?, ?, ?, ?, ?);
|
||||
INSERT
|
||||
OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config)
|
||||
VALUES (?, ?, ?, ?, ?);
|
@ -1,10 +1,7 @@
|
||||
delete from cards
|
||||
where
|
||||
nid in (
|
||||
select
|
||||
id
|
||||
from notes
|
||||
where
|
||||
mid = ?
|
||||
DELETE FROM cards
|
||||
WHERE nid IN (
|
||||
SELECT id
|
||||
FROM notes
|
||||
WHERE mid = ?
|
||||
)
|
||||
and ord = ?;
|
||||
AND ord = ?;
|
@ -1,27 +1,26 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
nid,
|
||||
ord,
|
||||
-- original deck
|
||||
(
|
||||
case
|
||||
CASE
|
||||
odid
|
||||
when 0 then did
|
||||
else odid
|
||||
end
|
||||
WHEN 0 THEN did
|
||||
ELSE odid
|
||||
END
|
||||
),
|
||||
-- new position if card is empty
|
||||
(
|
||||
case
|
||||
CASE
|
||||
type
|
||||
when 0 then (
|
||||
case
|
||||
WHEN 0 THEN (
|
||||
CASE
|
||||
odue
|
||||
when 0 then max(0, due)
|
||||
else max(odue, 0)
|
||||
end
|
||||
WHEN 0 THEN max(0, due)
|
||||
ELSE max(odue, 0)
|
||||
END
|
||||
)
|
||||
else null
|
||||
end
|
||||
ELSE NULL
|
||||
END
|
||||
)
|
||||
from cards c
|
||||
FROM cards c
|
@ -1,10 +1,6 @@
|
||||
select
|
||||
distinct name
|
||||
from fields
|
||||
where
|
||||
ntid in (
|
||||
select
|
||||
mid
|
||||
from notes
|
||||
where
|
||||
id in
|
||||
SELECT DISTINCT name
|
||||
FROM FIELDS
|
||||
WHERE ntid IN (
|
||||
SELECT mid
|
||||
FROM notes
|
||||
WHERE id IN
|
@ -1,9 +1,6 @@
|
||||
select
|
||||
ord,
|
||||
SELECT ord,
|
||||
name,
|
||||
config
|
||||
from fields
|
||||
where
|
||||
ntid = ?
|
||||
order by
|
||||
ord
|
||||
FROM FIELDS
|
||||
WHERE ntid = ?
|
||||
ORDER BY ord
|
@ -1,7 +1,6 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
name,
|
||||
mtime_secs,
|
||||
usn,
|
||||
config
|
||||
from notetypes
|
||||
FROM notetypes
|
@ -1,4 +1,3 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
name
|
||||
from notetypes
|
||||
FROM notetypes
|
@ -1,11 +1,8 @@
|
||||
select
|
||||
ord,
|
||||
SELECT ord,
|
||||
name,
|
||||
mtime_secs,
|
||||
usn,
|
||||
config
|
||||
from templates
|
||||
where
|
||||
ntid = ?
|
||||
order by
|
||||
ord
|
||||
FROM templates
|
||||
WHERE ntid = ?
|
||||
ORDER BY ord
|
@ -1,13 +1,9 @@
|
||||
select
|
||||
nt.id,
|
||||
SELECT nt.id,
|
||||
nt.name,
|
||||
(
|
||||
select
|
||||
count(*)
|
||||
from notes n
|
||||
where
|
||||
nt.id = n.mid
|
||||
SELECT COUNT(*)
|
||||
FROM notes n
|
||||
WHERE nt.id = n.mid
|
||||
)
|
||||
from notetypes nt
|
||||
order by
|
||||
nt.name
|
||||
FROM notetypes nt
|
||||
ORDER BY nt.name
|
@ -1,7 +1,7 @@
|
||||
select coalesce(max(ord), 0)
|
||||
from cards
|
||||
where nid in (
|
||||
select id
|
||||
from notes
|
||||
where mid = ?
|
||||
)
|
||||
SELECT coalesce(max(ord), 0)
|
||||
FROM cards
|
||||
WHERE nid IN (
|
||||
SELECT id
|
||||
FROM notes
|
||||
WHERE mid = ?
|
||||
)
|
@ -1,3 +1,2 @@
|
||||
insert into fields (ntid, ord, name, config)
|
||||
values
|
||||
(?, ?, ?, ?);
|
||||
INSERT INTO FIELDS (ntid, ord, name, config)
|
||||
VALUES (?, ?, ?, ?);
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or replace into notetype_config (ntid, config)
|
||||
values
|
||||
(?, ?)
|
||||
INSERT
|
||||
OR REPLACE INTO notetype_config (ntid, config)
|
||||
VALUES (?, ?)
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or replace into notetypes (id, name, mtime_secs, usn, config)
|
||||
values
|
||||
(?, ?, ?, ?, ?)
|
||||
INSERT
|
||||
OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config)
|
||||
VALUES (?, ?, ?, ?, ?)
|
@ -1,3 +1,2 @@
|
||||
insert into templates (ntid, ord, name, mtime_secs, usn, config)
|
||||
values
|
||||
(?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO templates (ntid, ord, name, mtime_secs, usn, config)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
@ -1,5 +1,5 @@
|
||||
insert
|
||||
or ignore into revlog (
|
||||
INSERT
|
||||
OR IGNORE INTO revlog (
|
||||
id,
|
||||
cid,
|
||||
usn,
|
||||
@ -10,18 +10,18 @@ insert
|
||||
time,
|
||||
type
|
||||
)
|
||||
values (
|
||||
VALUES (
|
||||
(
|
||||
case
|
||||
when ?1 in (
|
||||
select id
|
||||
from revlog
|
||||
) then (
|
||||
select max(id) + 1
|
||||
from revlog
|
||||
CASE
|
||||
WHEN ?1 IN (
|
||||
SELECT id
|
||||
FROM revlog
|
||||
) THEN (
|
||||
SELECT max(id) + 1
|
||||
FROM revlog
|
||||
)
|
||||
else ?1
|
||||
end
|
||||
ELSE ?1
|
||||
END
|
||||
),
|
||||
?,
|
||||
?,
|
||||
|
@ -1,7 +1,7 @@
|
||||
update revlog
|
||||
set ivl = min(max(round(ivl), -2147483648), 2147483647),
|
||||
UPDATE revlog
|
||||
SET ivl = min(max(round(ivl), -2147483648), 2147483647),
|
||||
lastIvl = min(max(round(lastIvl), -2147483648), 2147483647),
|
||||
time = min(max(round(time), 0), 2147483647)
|
||||
where ivl != min(max(round(ivl), -2147483648), 2147483647)
|
||||
or lastIvl != min(max(round(lastIvl), -2147483648), 2147483647)
|
||||
or time != min(max(round(time), 0), 2147483647)
|
||||
WHERE ivl != min(max(round(ivl), -2147483648), 2147483647)
|
||||
OR lastIvl != min(max(round(lastIvl), -2147483648), 2147483647)
|
||||
OR time != min(max(round(time), 0), 2147483647)
|
@ -1,5 +1,4 @@
|
||||
select
|
||||
id,
|
||||
SELECT id,
|
||||
cid,
|
||||
usn,
|
||||
ease,
|
||||
@ -8,4 +7,4 @@ select
|
||||
factor,
|
||||
time,
|
||||
type
|
||||
from revlog
|
||||
FROM revlog
|
@ -1,5 +1,5 @@
|
||||
select count(),
|
||||
coalesce(sum(time) / 1000.0, 0.0)
|
||||
from revlog
|
||||
where id > ?
|
||||
and type != ?
|
||||
SELECT COUNT(),
|
||||
coalesce(sum(time) / 1000.0, 0.0)
|
||||
FROM revlog
|
||||
WHERE id > ?
|
||||
AND type != ?
|
@ -1,88 +1,92 @@
|
||||
create table col
|
||||
(
|
||||
id integer primary key,
|
||||
crt integer not null,
|
||||
mod integer not null,
|
||||
scm integer not null,
|
||||
ver integer not null,
|
||||
dty integer not null,
|
||||
usn integer not null,
|
||||
ls integer not null,
|
||||
conf text not null,
|
||||
models text not null,
|
||||
decks text not null,
|
||||
dconf text not null,
|
||||
tags text not null
|
||||
CREATE TABLE col (
|
||||
id integer PRIMARY KEY,
|
||||
crt integer NOT NULL,
|
||||
mod integer NOT NULL,
|
||||
scm integer NOT NULL,
|
||||
ver integer NOT NULL,
|
||||
dty integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
ls integer NOT NULL,
|
||||
conf text NOT NULL,
|
||||
models text NOT NULL,
|
||||
decks text NOT NULL,
|
||||
dconf text NOT NULL,
|
||||
tags text NOT NULL
|
||||
);
|
||||
|
||||
create table notes
|
||||
(
|
||||
id integer primary key,
|
||||
guid text not null,
|
||||
mid integer not null,
|
||||
mod integer not null,
|
||||
usn integer not null,
|
||||
tags text not null,
|
||||
flds text not null,
|
||||
sfld integer not null,
|
||||
csum integer not null,
|
||||
flags integer not null,
|
||||
data text not null
|
||||
CREATE TABLE notes (
|
||||
id integer PRIMARY KEY,
|
||||
guid text NOT NULL,
|
||||
mid integer NOT NULL,
|
||||
mod integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
tags text NOT NULL,
|
||||
flds text NOT NULL,
|
||||
sfld integer NOT NULL,
|
||||
csum integer NOT NULL,
|
||||
flags integer NOT NULL,
|
||||
data text NOT NULL
|
||||
);
|
||||
|
||||
create table cards
|
||||
(
|
||||
id integer primary key,
|
||||
nid integer not null,
|
||||
did integer not null,
|
||||
ord integer not null,
|
||||
mod integer not null,
|
||||
usn integer not null,
|
||||
type integer not null,
|
||||
queue integer not null,
|
||||
due integer not null,
|
||||
ivl integer not null,
|
||||
factor integer not null,
|
||||
reps integer not null,
|
||||
lapses integer not null,
|
||||
left integer not null,
|
||||
odue integer not null,
|
||||
odid integer not null,
|
||||
flags integer not null,
|
||||
data text not null
|
||||
CREATE TABLE cards (
|
||||
id integer PRIMARY KEY,
|
||||
nid integer NOT NULL,
|
||||
did integer NOT NULL,
|
||||
ord integer NOT NULL,
|
||||
mod integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
type integer NOT NULL,
|
||||
queue integer NOT NULL,
|
||||
due integer NOT NULL,
|
||||
ivl integer NOT NULL,
|
||||
factor integer NOT NULL,
|
||||
reps integer NOT NULL,
|
||||
lapses integer NOT NULL,
|
||||
left integer NOT NULL,
|
||||
odue integer NOT NULL,
|
||||
odid integer NOT NULL,
|
||||
flags integer NOT NULL,
|
||||
data text NOT NULL
|
||||
);
|
||||
|
||||
create table revlog
|
||||
(
|
||||
id integer primary key,
|
||||
cid integer not null,
|
||||
usn integer not null,
|
||||
ease integer not null,
|
||||
ivl integer not null,
|
||||
lastIvl integer not null,
|
||||
factor integer not null,
|
||||
time integer not null,
|
||||
type integer not null
|
||||
CREATE TABLE revlog (
|
||||
id integer PRIMARY KEY,
|
||||
cid integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
ease integer NOT NULL,
|
||||
ivl integer NOT NULL,
|
||||
lastIvl integer NOT NULL,
|
||||
factor integer NOT NULL,
|
||||
time integer NOT NULL,
|
||||
type integer NOT NULL
|
||||
);
|
||||
|
||||
create table graves
|
||||
(
|
||||
usn integer not null,
|
||||
oid integer not null,
|
||||
type integer not null
|
||||
CREATE TABLE graves (
|
||||
usn integer NOT NULL,
|
||||
oid integer NOT NULL,
|
||||
type integer NOT NULL
|
||||
);
|
||||
|
||||
-- syncing
|
||||
create index ix_notes_usn on notes (usn);
|
||||
create index ix_cards_usn on cards (usn);
|
||||
create index ix_revlog_usn on revlog (usn);
|
||||
CREATE INDEX ix_notes_usn ON notes (usn);
|
||||
CREATE INDEX ix_cards_usn ON cards (usn);
|
||||
CREATE INDEX ix_revlog_usn ON revlog (usn);
|
||||
-- card spacing, etc
|
||||
create index ix_cards_nid on cards (nid);
|
||||
CREATE INDEX ix_cards_nid ON cards (nid);
|
||||
-- scheduling and deck limiting
|
||||
create index ix_cards_sched on cards (did, queue, due);
|
||||
CREATE INDEX ix_cards_sched ON cards (did, queue, due);
|
||||
-- revlog by card
|
||||
create index ix_revlog_cid on revlog (cid);
|
||||
CREATE INDEX ix_revlog_cid ON revlog (cid);
|
||||
-- field uniqueness
|
||||
create index ix_notes_csum on notes (csum);
|
||||
|
||||
insert into col values (1,0,0,0,0,0,0,0,'{}','{}','{}','{}','{}');
|
||||
CREATE INDEX ix_notes_csum ON notes (csum);
|
||||
INSERT INTO col
|
||||
VALUES (
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'{}',
|
||||
'{}',
|
||||
'{}',
|
||||
'{}',
|
||||
'{}'
|
||||
);
|
@ -1,4 +1,3 @@
|
||||
insert
|
||||
or ignore into tags (tag, usn)
|
||||
values
|
||||
(?, ?)
|
||||
INSERT
|
||||
OR IGNORE INTO tags (tag, usn)
|
||||
VALUES (?, ?)
|
@ -1,12 +1,11 @@
|
||||
drop table config;
|
||||
drop table deck_config;
|
||||
drop table tags;
|
||||
drop table fields;
|
||||
drop table templates;
|
||||
drop table notetypes;
|
||||
drop table decks;
|
||||
drop index idx_cards_odid;
|
||||
drop index idx_notes_mid;
|
||||
update col
|
||||
set
|
||||
ver = 11;
|
||||
DROP TABLE config;
|
||||
DROP TABLE deck_config;
|
||||
DROP TABLE tags;
|
||||
DROP TABLE FIELDS;
|
||||
DROP TABLE templates;
|
||||
DROP TABLE notetypes;
|
||||
DROP TABLE decks;
|
||||
DROP INDEX idx_cards_odid;
|
||||
DROP INDEX idx_notes_mid;
|
||||
UPDATE col
|
||||
SET ver = 11;
|
@ -1,20 +1,19 @@
|
||||
create table deck_config (
|
||||
id integer primary key not null,
|
||||
name text not null collate unicase,
|
||||
mtime_secs integer not null,
|
||||
usn integer not null,
|
||||
config blob not null
|
||||
CREATE TABLE deck_config (
|
||||
id integer PRIMARY KEY NOT NULL,
|
||||
name text NOT NULL COLLATE unicase,
|
||||
mtime_secs integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
config blob NOT NULL
|
||||
);
|
||||
create table config (
|
||||
key text not null primary key,
|
||||
usn integer not null,
|
||||
mtime_secs integer not null,
|
||||
val blob not null
|
||||
CREATE TABLE config (
|
||||
KEY text NOT NULL PRIMARY KEY,
|
||||
usn integer NOT NULL,
|
||||
mtime_secs integer NOT NULL,
|
||||
val blob NOT NULL
|
||||
) without rowid;
|
||||
create table tags (
|
||||
tag text not null primary key collate unicase,
|
||||
usn integer not null
|
||||
CREATE TABLE tags (
|
||||
tag text NOT NULL PRIMARY KEY COLLATE unicase,
|
||||
usn integer NOT NULL
|
||||
) without rowid;
|
||||
update col
|
||||
set
|
||||
ver = 14;
|
||||
UPDATE col
|
||||
SET ver = 14;
|
@ -1,45 +1,43 @@
|
||||
create table fields (
|
||||
ntid integer not null,
|
||||
ord integer not null,
|
||||
name text not null collate unicase,
|
||||
config blob not null,
|
||||
primary key (ntid, ord)
|
||||
CREATE TABLE FIELDS (
|
||||
ntid integer NOT NULL,
|
||||
ord integer NOT NULL,
|
||||
name text NOT NULL COLLATE unicase,
|
||||
config blob NOT NULL,
|
||||
PRIMARY KEY (ntid, ord)
|
||||
) without rowid;
|
||||
create unique index idx_fields_name_ntid on fields (name, ntid);
|
||||
create table templates (
|
||||
ntid integer not null,
|
||||
ord integer not null,
|
||||
name text not null collate unicase,
|
||||
mtime_secs integer not null,
|
||||
usn integer not null,
|
||||
config blob not null,
|
||||
primary key (ntid, ord)
|
||||
CREATE UNIQUE INDEX idx_fields_name_ntid ON FIELDS (name, ntid);
|
||||
CREATE TABLE templates (
|
||||
ntid integer NOT NULL,
|
||||
ord integer NOT NULL,
|
||||
name text NOT NULL COLLATE unicase,
|
||||
mtime_secs integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
config blob NOT NULL,
|
||||
PRIMARY KEY (ntid, ord)
|
||||
) without rowid;
|
||||
create unique index idx_templates_name_ntid on templates (name, ntid);
|
||||
create index idx_templates_usn on templates (usn);
|
||||
create table notetypes (
|
||||
id integer not null primary key,
|
||||
name text not null collate unicase,
|
||||
mtime_secs integer not null,
|
||||
usn integer not null,
|
||||
config blob not null
|
||||
CREATE UNIQUE INDEX idx_templates_name_ntid ON templates (name, ntid);
|
||||
CREATE INDEX idx_templates_usn ON templates (usn);
|
||||
CREATE TABLE notetypes (
|
||||
id integer NOT NULL PRIMARY KEY,
|
||||
name text NOT NULL COLLATE unicase,
|
||||
mtime_secs integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
config blob NOT NULL
|
||||
);
|
||||
create unique index idx_notetypes_name on notetypes (name);
|
||||
create index idx_notetypes_usn on notetypes (usn);
|
||||
create table decks (
|
||||
id integer primary key not null,
|
||||
name text not null collate unicase,
|
||||
mtime_secs integer not null,
|
||||
usn integer not null,
|
||||
common blob not null,
|
||||
kind blob not null
|
||||
CREATE UNIQUE INDEX idx_notetypes_name ON notetypes (name);
|
||||
CREATE INDEX idx_notetypes_usn ON notetypes (usn);
|
||||
CREATE TABLE decks (
|
||||
id integer PRIMARY KEY NOT NULL,
|
||||
name text NOT NULL COLLATE unicase,
|
||||
mtime_secs integer NOT NULL,
|
||||
usn integer NOT NULL,
|
||||
common blob NOT NULL,
|
||||
kind blob NOT NULL
|
||||
);
|
||||
create unique index idx_decks_name on decks (name);
|
||||
create index idx_notes_mid on notes (mid);
|
||||
create index idx_cards_odid on cards (odid)
|
||||
where
|
||||
odid != 0;
|
||||
update col
|
||||
set
|
||||
ver = 15;
|
||||
analyze;
|
||||
CREATE UNIQUE INDEX idx_decks_name ON decks (name);
|
||||
CREATE INDEX idx_notes_mid ON notes (mid);
|
||||
CREATE INDEX idx_cards_odid ON cards (odid)
|
||||
WHERE odid != 0;
|
||||
UPDATE col
|
||||
SET ver = 15;
|
||||
ANALYZE;
|
@ -1,7 +1,18 @@
|
||||
load("//ts:prettier.bzl", "prettier")
|
||||
load("//ts:prettier.bzl", "prettier", "prettier_test")
|
||||
load("//ts:sql_format.bzl", "sql_format_setup")
|
||||
|
||||
prettier()
|
||||
|
||||
prettier_test(
|
||||
name = "format_check",
|
||||
srcs = glob([
|
||||
"*.ts",
|
||||
"*.js",
|
||||
]),
|
||||
)
|
||||
|
||||
sql_format_setup()
|
||||
|
||||
# Exported files
|
||||
#################
|
||||
|
||||
@ -12,6 +23,7 @@ exports_files([
|
||||
"rollup.config.js",
|
||||
".eslintrc.js",
|
||||
"licenses.json",
|
||||
"sql_format.ts",
|
||||
])
|
||||
|
||||
alias(
|
||||
|
@ -197,7 +197,7 @@ export function renderCards(
|
||||
|
||||
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
||||
|
||||
const tableData = (data as any).flatMap((d: SummedDatum, idx: number) => {
|
||||
const tableData = data.flatMap((d: SummedDatum, idx: number) => {
|
||||
const percent = ((d.count / xMax) * 100).toFixed(1);
|
||||
return d.show
|
||||
? ({
|
||||
|
@ -9,7 +9,7 @@
|
||||
import type pb from "anki/backend_proto";
|
||||
import { extent, histogram, sum } from "d3-array";
|
||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
||||
import { CardQueue } from "anki/cards";
|
||||
import { CardType } from "anki/cards";
|
||||
import type { HistogramData } from "./histogram-graph";
|
||||
import { interpolateRdYlGn } from "d3-scale-chromatic";
|
||||
import type { I18n } from "anki/i18n";
|
||||
@ -21,7 +21,7 @@ export interface GraphData {
|
||||
|
||||
export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
|
||||
const eases = (data.cards as pb.BackendProto.Card[])
|
||||
.filter((c) => c.queue == CardQueue.Review)
|
||||
.filter((c) => [CardType.Review, CardType.Relearn].includes(c.ctype))
|
||||
.map((c) => c.easeFactor / 10);
|
||||
return { eases };
|
||||
}
|
||||
|
@ -67,33 +67,48 @@ export function prepareIntervalData(
|
||||
return [null, []];
|
||||
}
|
||||
|
||||
const [_xMinOrig, origXMax] = extent(allIntervals);
|
||||
let xMax = origXMax;
|
||||
const xMin = 0;
|
||||
let [, xMax] = extent(allIntervals);
|
||||
let niceNecessary = false;
|
||||
|
||||
// cap max to selected range
|
||||
switch (range) {
|
||||
case IntervalRange.Month:
|
||||
xMax = Math.min(xMax!, 31);
|
||||
xMax = Math.min(xMax!, 30);
|
||||
break;
|
||||
case IntervalRange.Percentile50:
|
||||
xMax = quantile(allIntervals, 0.5);
|
||||
niceNecessary = true;
|
||||
break;
|
||||
case IntervalRange.Percentile95:
|
||||
xMax = quantile(allIntervals, 0.95);
|
||||
niceNecessary = true;
|
||||
break;
|
||||
case IntervalRange.All:
|
||||
niceNecessary = true;
|
||||
break;
|
||||
}
|
||||
const xMin = 0;
|
||||
|
||||
xMax = xMax! + 1;
|
||||
|
||||
// do not show the zero interval
|
||||
const increment = (x: number): number => x + 1;
|
||||
|
||||
const adjustTicks = (x: number, idx: number, ticks: number[]): number[] =>
|
||||
idx === ticks.length - 1 ? [x - (ticks[0] - 1), x + 1] : [x - (ticks[0] - 1)];
|
||||
|
||||
// cap bars to available range
|
||||
const desiredBars = Math.min(70, xMax! - xMin!);
|
||||
|
||||
const scale = scaleLinear().domain([xMin!, xMax!]).nice();
|
||||
const prescale = scaleLinear().domain([xMin!, xMax!]);
|
||||
|
||||
const scale = scaleLinear().domain(
|
||||
(niceNecessary ? prescale.nice() : prescale).domain().map(increment)
|
||||
);
|
||||
|
||||
const bins = histogram()
|
||||
.domain(scale.domain() as any)
|
||||
.thresholds(scale.ticks(desiredBars))(allIntervals);
|
||||
.domain(scale.domain() as [number, number])
|
||||
.thresholds(scale.ticks(desiredBars).flatMap(adjustTicks))(allIntervals);
|
||||
|
||||
// empty graph?
|
||||
const totalInPeriod = sum(bins, (bin) => bin.length);
|
||||
|
@ -12,6 +12,7 @@
|
||||
"@pyoner/svelte-types": "^3.4.4-2",
|
||||
"@rollup/plugin-commonjs": "^15.1.0",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||
"@sqltools/formatter": "^1.2.2",
|
||||
"@tsconfig/svelte": "^1.0.10",
|
||||
"@types/d3-array": "^2.0.0",
|
||||
"@types/d3-axis": "^1.0.12",
|
||||
@ -22,15 +23,18 @@
|
||||
"@types/d3-shape": "^1.3.2",
|
||||
"@types/d3-time": "^2.0.0",
|
||||
"@types/d3-transition": "^1.1.6",
|
||||
"@types/diff": "^5.0.0",
|
||||
"@types/jquery": "^3.5.0",
|
||||
"@types/jqueryui": "^1.12.13",
|
||||
"@types/lodash": "^4.14.162",
|
||||
"@types/long": "^4.0.1",
|
||||
"@types/node": "^14.14.20",
|
||||
"@types/react": "^16.9.53",
|
||||
"@types/react-dom": "^16.9.8",
|
||||
"@typescript-eslint/eslint-plugin": "^2.11.0",
|
||||
"@typescript-eslint/parser": "^2.11.0",
|
||||
"cross-env": "^7.0.2",
|
||||
"diff": "^5.0.0",
|
||||
"eslint": "^6.7.2",
|
||||
"license-checker-rseidelsohn": "=1.1.2",
|
||||
"patch-package": "^6.2.2",
|
||||
|
24
ts/sql_format.bzl
Normal file
24
ts/sql_format.bzl
Normal file
@ -0,0 +1,24 @@
|
||||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
|
||||
|
||||
def sql_format_setup():
|
||||
ts_library(
|
||||
name = "sql_format_lib",
|
||||
srcs = ["//ts:sql_format.ts"],
|
||||
deps = [
|
||||
"@npm//@sqltools/formatter",
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/diff",
|
||||
"@npm//diff",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
def sql_format(name = "sql_format", srcs = [], **kwargs):
|
||||
nodejs_test(
|
||||
name = name,
|
||||
entry_point = "//ts:sql_format.ts",
|
||||
args = [native.package_name() + "/" + f for f in srcs],
|
||||
data = ["//ts:sql_format_lib", "@npm//tslib", "@npm//diff"] + srcs,
|
||||
**kwargs
|
||||
)
|
46
ts/sql_format.ts
Normal file
46
ts/sql_format.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import sqlFormatter from "@sqltools/formatter";
|
||||
import * as Diff from "diff";
|
||||
import process from "process";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
const workspace = process.env.BUILD_WORKSPACE_DIRECTORY;
|
||||
const wantFix = workspace !== undefined;
|
||||
|
||||
function fixFile(relpath: string, newText: string): void {
|
||||
const workspacePath = path.join(workspace!, relpath);
|
||||
fs.writeFileSync(workspacePath, newText);
|
||||
}
|
||||
|
||||
function formatText(text: string): string {
|
||||
const newText: string = sqlFormatter.format(text, {
|
||||
indent: " ",
|
||||
reservedWordCase: "upper",
|
||||
});
|
||||
// 'type' is treated as a reserved word, but Anki uses it in various sql
|
||||
// tables, so we don't want it uppercased
|
||||
return newText.replace(/\bTYPE\b/g, "type");
|
||||
}
|
||||
|
||||
let errorFound = false;
|
||||
for (const path of process.argv.slice(2)) {
|
||||
const orig = fs.readFileSync(path).toString();
|
||||
const formatted = formatText(orig);
|
||||
if (orig !== formatted) {
|
||||
if (wantFix) {
|
||||
fixFile(path, formatted);
|
||||
console.log(`Fixed ${path}`);
|
||||
} else {
|
||||
if (!errorFound) {
|
||||
errorFound = true;
|
||||
console.log("SQL formatting issues found:");
|
||||
}
|
||||
console.log(Diff.createPatch(path, orig, formatted));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errorFound) {
|
||||
console.log("Use 'bazel run //rslib:sql_format' to fix.");
|
||||
console.log(process.env.BUILD_WORKSPACE_DIRECTORY);
|
||||
process.exit(1);
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "es6",
|
||||
"lib": ["es2016", "dom"],
|
||||
"lib": ["es2016", "es2019.array", "dom"],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"anki/*": ["../bazel-bin/ts/lib/*"]
|
||||
@ -24,7 +24,7 @@
|
||||
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
"jsx": "react",
|
||||
"types": ["svelte", "long"],
|
||||
"types": ["svelte", "long", "node"],
|
||||
"noEmitHelpers": true,
|
||||
"importHelpers": true
|
||||
}
|
||||
|
20
ts/yarn.lock
20
ts/yarn.lock
@ -145,6 +145,11 @@
|
||||
estree-walker "^1.0.1"
|
||||
picomatch "^2.2.2"
|
||||
|
||||
"@sqltools/formatter@^1.2.2":
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/@sqltools/formatter/-/formatter-1.2.2.tgz#9390a8127c0dcba61ebd7fdcc748655e191bdd68"
|
||||
integrity sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q==
|
||||
|
||||
"@tsconfig/svelte@^1.0.10":
|
||||
version "1.0.10"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/svelte/-/svelte-1.0.10.tgz#30ec7feeee0bdf38b12a50f0686f8a2e7b6b9dc0"
|
||||
@ -220,6 +225,11 @@
|
||||
dependencies:
|
||||
"@types/d3-selection" "^1"
|
||||
|
||||
"@types/diff@^5.0.0":
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-5.0.0.tgz#eb71e94feae62548282c4889308a3dfb57e36020"
|
||||
integrity sha512-jrm2K65CokCCX4NmowtA+MfXyuprZC13jbRuwprs6/04z/EcFg/MCwYdsHn+zgV4CQBiATiI7AEq7y1sZCtWKA==
|
||||
|
||||
"@types/eslint-visitor-keys@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
|
||||
@ -279,6 +289,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.38.tgz#66a7c068305dbd64cf167d0f6b6b6be71dd453e1"
|
||||
integrity sha512-oxo8j9doh7ab9NwDA9bCeFfjHRF/uzk+fTljCy8lMjZ3YzZGAXNDKhTE3Byso/oy32UTUQIXB3HCVHu3d2T3xg==
|
||||
|
||||
"@types/node@^14.14.20":
|
||||
version "14.14.20"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.20.tgz#f7974863edd21d1f8a494a73e8e2b3658615c340"
|
||||
integrity sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==
|
||||
|
||||
"@types/prop-types@*":
|
||||
version "15.7.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
|
||||
@ -959,6 +974,11 @@ dezalgo@^1.0.0:
|
||||
asap "^2.0.0"
|
||||
wrappy "1"
|
||||
|
||||
diff@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b"
|
||||
integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==
|
||||
|
||||
doctrine@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
|
||||
|
Loading…
Reference in New Issue
Block a user