Anki/anki/graves.py
Damien Elmes 55f4b9b7d0 favour integers, change due representation, fact&card ordering, more
- removed 'created' column from various tables. We don't care when things like
  models are created, and card creation time didn't reflect the actual time a
  card was created
- facts were previously ordered by their creation date. The code would
  manually set the creation time for subsequent facts on import by 0.0001
  seconds, and then card due times were set by adding the fact time to the
  ordinal number*0.000001. This was prone to error, and the number of zeros used
  was actually different in different parts of the code. Instead of this, we
  replace it with a 'pos' column on facts, which increments for each new fact.
- importing should add new facts with a higher pos, but concurrent updates in
  a synced deck can have multiple facts with the same pos

- due times are completely different now, and depend on the card type
- new cards have due=fact.pos or random(0, 10000)
- reviews have due set to an integer representing days since deck
  creation/download
- cards in the learn queue use an integer timestamp in seconds

- many columns like modified, lastSync, factor, interval, etc have been converted to
  integer columns. They are cheaper to store (large decks can save 10s of
  megabytes) and faster to search for.

- cards have their group assigned on fact creation. In the future we'll add a
  per-template option for a default group.

- switch to due/random order for the review queue on upgrade. Users can still
  switch to the old behaviour if they want, but many people don't care what
  it's set to, and due is considerably faster, which may result in a better
  user experience
2011-04-28 09:23:28 +09:00

35 lines
943 B
Python

# -*- coding: utf-8 -*-
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
# FIXME:
# - check if we have to int(time)
# - port all the code referencing the old tables
import time
from anki.db import *
from anki.utils import intTime
FACT = 0
CARD = 1
MODEL = 2
MEDIA = 3
GROUP = 4
GROUPCONFIG = 5
gravestonesTable = Table(
'gravestones', metadata,
Column('delTime', Integer, nullable=False),
Column('objectId', Integer, nullable=False),
Column('type', Integer, nullable=False))
def registerOne(db, type, id):
db.statement("insert into gravestones values (:t, :id, :ty)",
t=intTime(), id=id, ty=type)
def registerMany(db, type, ids):
db.statements("insert into gravestones values (:t, :id, :ty)",
[{'t':intTime(), 'id':x, 'ty':type} for x in ids])
def forgetAll(db):
db.statement("delete from gravestones")