mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00

The tags tables were initially added to speed up the loading of the browser by speeding up two operations: gathering a list of all tags to show in the dropdown box, and finding cards with a given tag. The former functionality is provided by the tags table, and the latter functionality by the cardTags table. Selective study is handled by groups now, which perform better since they don't require a join or subselect, and can be embedded in the index. So the only remaining benefit of cardTags is for the browser. Performance testing indicates that cardTags is not saving us a large amount. It only takes us 30ms to search a 50k card table for matches with a hot cache. On a cold cache it means the facts table has to be loaded into memory, which roughly doubles the load time with the default settings (we need to load the cards table too, as we're sorting the cards), but that startup time was necessary with certain settings in the past too (sorting by fact created for example). With groups implemented, the cost of maintaining a cache just for initial browser load time is hard to justify. Other changes: - the tags table has any missing tags added to it when facts are added/edited. This means old tags will stick around even when no cards reference them, but is much cheaper than reference counting or a separate table, and simplifies updates and syncing. - the tags table has a modified field now so we can can sync it instead of having to scan all facts coming across in a sync - priority field removed - we no longer put model names or card templates into the tags table. There were two reasons we did this in the past: so we could cram/selective study them, and for plugins. Selective study uses groups now, and plugins can check the model's name instead (and most already do). This also does away with the somewhat confusing behaviour of names also being tags. - facts have their tags as _tags now. You can get a list with tags(), but editing operations should use add/deleteTags() instead of manually editing the string.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
|
|
|
"""\
|
|
Standard Models.
|
|
==============================================================
|
|
|
|
Plugins can add to the 'models' dict to provide more standard
|
|
models.
|
|
"""
|
|
|
|
from anki.models import Model, CardModel, FieldModel
|
|
from anki.lang import _
|
|
|
|
models = {}
|
|
|
|
def byName(name):
|
|
fn = models.get(name)
|
|
if fn:
|
|
return fn()
|
|
raise ValueError("No such model available!")
|
|
|
|
def names():
|
|
return models.keys()
|
|
|
|
# Basic
|
|
##########################################################################
|
|
|
|
def BasicModel():
|
|
m = Model(_('Basic'))
|
|
m.addFieldModel(FieldModel(u'Front', True, True))
|
|
m.addFieldModel(FieldModel(u'Back', False, False))
|
|
m.addCardModel(CardModel(u'Forward', u'%(Front)s', u'%(Back)s'))
|
|
m.addCardModel(CardModel(u'Reverse', u'%(Back)s', u'%(Front)s',
|
|
active=False))
|
|
return m
|
|
|
|
models['Basic'] = BasicModel
|
|
|
|
# Recovery
|
|
##########################################################################
|
|
|
|
def RecoveryModel():
|
|
m = Model(_('Recovery'))
|
|
m.addFieldModel(FieldModel(u'Question', False, False))
|
|
m.addFieldModel(FieldModel(u'Answer', False, False))
|
|
m.addCardModel(CardModel(u'Single', u'{{{Question}}}', u'{{{Answer}}}'))
|
|
return m
|