mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00

Anki used random 64bit IDs for cards, facts and fields. This had some nice properties: - merging data in syncs and imports was simply a matter of copying each way, as conflicts were astronomically unlikely - it made it easy to identify identical cards and prevent them from being reimported But there were some negatives too: - they're more expensive to store - javascript can't handle numbers > 2**53, which means AnkiMobile, iAnki and so on have to treat the ids as strings, which is slow - simply copying data in a sync or import can lead to corruption, as while a duplicate id indicates the data was originally the same, it may have diverged. A more intelligent approach is necessary. - sqlite was sorting the fields table based on the id, which meant the fields were spread across the table, and costly to fetch So instead, we'll move to incremental ids. In the case of model changes we'll declare that a schema change and force a full sync to avoid having to deal with conflicts, and in the case of cards and facts, we'll need to update the ids on one end to merge. Identical cards can be detected by checking to see if their id is the same and their creation time is the same. Creation time has been added back to cards and facts because it's necessary for sync conflict merging. That means facts.pos is not required. The graves table has been removed. It's not necessary for schema related changes, and dead cards/facts can be represented as a card with queue=-4 and created=0. Because we will record schema modification time and can ensure a full sync propagates to all endpoints, it means we can remove the dead cards/facts on schema change. Tags have been removed from the facts table and are represented as a field with ord=-1 and fmid=0. Combined with the locality improvement for fields, it means that fetching fields is not much more expensive than using the q/a cache. Because of the above, removing the q/a cache is a possibility now. The q and a columns on cards has been dropped. It will still be necessary to render the q/a on fact add/edit, since we need to record media references. It would be nice to avoid this in the future. Perhaps one way would be the ability to assign a type to fields, like "image", "audio", or "latex". LaTeX needs special consider anyway, as it was being rendered into the q/a cache.
39 lines
1,020 B
Python
39 lines
1,020 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
|
|
|
|
import simplejson, time
|
|
from anki.utils import intTime
|
|
|
|
# maybe define a random cutoff at say +/-30% which controls exit interval
|
|
# variation - 30% of 1 day is 0.7 or 1.3 so always 1 day; 30% of 4 days is
|
|
# 2.8-5.2, so any time from 3-5 days is acceptable
|
|
|
|
defaultConf = {
|
|
'new': {
|
|
'delays': [0.5, 3, 10],
|
|
'ints': [1, 7, 4],
|
|
'initialFactor': 2.5,
|
|
},
|
|
'lapse': {
|
|
'delays': [0.5, 3, 10],
|
|
'ints': [1, 7, 4],
|
|
'mult': 0
|
|
},
|
|
'suspendLeeches': True,
|
|
'leechFails': 16,
|
|
}
|
|
|
|
class GroupConfig(object):
|
|
def __init__(self, name):
|
|
self.name = name
|
|
self.id = None
|
|
self.config = defaultConf
|
|
|
|
def load(self):
|
|
self.config = simplejson.loads(self._config)
|
|
return self
|
|
|
|
def save(self):
|
|
self._config = simplejson.dumps(self.config)
|
|
self.modified = intTime()
|