Commit graph

707 commits

Author SHA1 Message Date
Damien Elmes
be5c5a2018 move tags into deck; code into separate file
- moved tags into json like previous changes, and dropped the unnecessary id
- added tags.py for a tag manager
- moved the tag utilities from utils into tags.py
2011-08-28 13:44:29 +09:00
Damien Elmes
d20984a686 fix upgrade 2011-08-28 00:20:24 +09:00
Damien Elmes
78600e8ed6 move group code into a registry like models 2011-08-27 23:45:55 +09:00
Damien Elmes
d3a3edb707 move models into the deck table
Like the previous change, models have been moved from a separate DB table to
an entry in the deck. We need them for many operations including reviewing,
and it's easier to keep them in memory than half on disk with a cache that
gets cleared every time we .reset(). This means they are easily serialized as
well - previously they were part Python and part JSON, which made access
confusing.

Because the data is all pulled from JSON now, the instance methods have been
moved to the model registry. Eg:
  model.addField(...) -> deck.models.addField(model, ...).

- IDs are now timestamped as with groups et al.

- The data field for plugins was also removed. Config info can be added to
  deck.conf; larger data should be stored externally.

- Upgrading needs to be updated for the new model structure.

- HexifyID() now accepts strings as well, as our IDs get converted to strings
  in the serialization process.
2011-08-27 22:27:09 +09:00
Damien Elmes
7afe6a9a7d convert groups to json; use timestamp ids for all but default
Rather than use a combination of id lookups on the groups table and a group
configuration cache in the scheduler, I've moved the groups and group config
into json objects on the deck table. This results in a net saving of code and
saves one or more DB lookups on each card answer, in exchange for a small
increase in deck load/save work.

I did a quick survey of AnkiWeb, and the vast majority of decks use less than
100 tags, and it's safe to assume groups will follow a similar pattern.

All groups and group configs except the default one will use integer
timestamps now, to simplify merging when syncing and importing.

defaultGroup() has been removed in favour of keeping the models up to date
(not yet done).
2011-08-27 17:13:04 +09:00
Damien Elmes
47be8b0546 use the timestamps instead of forcing id on fact/card creation
- we ditch nextCid/nextFid as we don't need incrementing ids anymore
- we add nextPos so we can maintain a user-friendly position number
2011-08-27 00:36:39 +09:00
Damien Elmes
644a885a07 update fact ids, graves
- should never skip recording graves, for the sake of merging
- 1.0 upgrade will fail on decks that have the same fact creation date. need
      to work around this in the future
2011-08-26 21:23:16 +09:00
Damien Elmes
6644c04852 start work on id refactor - models first
The approach of using incrementing id numbers works for syncing if we assume
the server is canonical and all other clients rewrite their ids as necessary,
but upon reflection it is not sufficient for merging decks in general, as we
have no way of knowing whether objects with the same id are actually the same
or not. So we need some way of uniquely identifying the object.

One approach would be to go back to Anki 1.0's random 64bit numbers, but as
outlined in a previous commit such large numbers can't be handled easy in some
languages like Javascript, and they tend to be fragmented on disk which
impacts performance. It's much better if we can keep content added at the same
time in the same place on disk, so that operations like syncing which are mainly
interested in newly added content can run faster.

Another approach is to add a separate column containing the unique id, which
is what Mnemosyne 2.0 will be doing. Unfortunately it means adding an index
for that column, leading to slower inserts and larger deck files. And if the
current sequential ids are kept, a bunch of code needs to be kept to ensure ids
don't conflict when merging.

To address the above, the plan is to use a millisecond timestamp as the id.
This ensures disk order reflects creation order, allows us to merge the id and
crt columns, avoids the need for a separate index, and saves us from worrying
about rewriting ids. There is of course a small chance that the objects to be
merged were created at exactly the same time, but this is extremely unlikely.

This commit changes models. Other objects will follow.
2011-08-26 21:08:30 +09:00
Damien Elmes
9de16289ba always mark gravestones 2011-08-26 17:28:59 +09:00
Damien Elmes
6627264079 delFacts() convenience method; mod schema on model add 2011-05-08 02:12:09 +09:00
Damien Elmes
0af03a6a8a only use deletion log when necessary 2011-05-07 21:45:55 +09:00
Damien Elmes
ec8c720048 make it possible to save with a given mod time, for use in syncing 2011-05-04 23:27:56 +09:00
Damien Elmes
3d370f675b restore the deletion log
the initial plan was to zero the creation time and leave the cards/facts there
until we have a chance to garbage collect them on a schema change, but such an
approach won't work with deck subscriptions
2011-05-04 19:00:38 +09:00
Damien Elmes
5856ad7545 make latex pre/postamble a model property 2011-04-28 09:24:05 +09:00
Damien Elmes
19fd581839 change default lrn timing; leechAction doesn't need an array 2011-04-28 09:24:05 +09:00
Damien Elmes
0d6064b933 rename() 2011-04-28 09:24:05 +09:00
Damien Elmes
d1deeb2b37 keep track of session reps in scheduler 2011-04-28 09:24:05 +09:00
Damien Elmes
431fd2585e when adding cards, use rand(1, maxfid)
this means that content added earlier has a higher chance of appearing, but it
makes it consistent with sortCards(), and the user can sort manually if need
be
2011-04-28 09:24:04 +09:00
Damien Elmes
1641256da4 random ids should start at 1 2011-04-28 09:24:04 +09:00
Damien Elmes
82c3119c90 update randomizing/ordering code and forgetCards()
instead of completely resetting a card like we did in resetCards() in the
past, forgetCards() just puts the card back in the new queue and leaves the
factor and revlog alone. If users want to complete reset a card, they'll need to
export it.
2011-04-28 09:24:04 +09:00
Damien Elmes
7d64036a07 drop streak, make reps log all entries
reps should now be equal to the number of entries in the revlog, and only
exists so that we can order by review count in the browser efficiently

streak is no longer necessary as we have a learn queue now
2011-04-28 09:24:04 +09:00
Damien Elmes
2243b691cc add full search to ignore formatting 2011-04-28 09:24:03 +09:00
Damien Elmes
03d00228aa support stripping context of cloze 2011-04-28 09:24:03 +09:00
Damien Elmes
aac840f375 remove redundant cardHasTag() 2011-04-28 09:24:03 +09:00
Damien Elmes
84d59e4b01 don't truncate sort field anymore, since we display it in the gui 2011-04-28 09:24:03 +09:00
Damien Elmes
8b747c3aac allow the user to choose if case should be folded 2011-04-28 09:24:03 +09:00
Damien Elmes
d51cd5a433 find & replace 2011-04-28 09:24:03 +09:00
Damien Elmes
93d80678f9 _fields -> fields 2011-04-28 09:24:02 +09:00
Damien Elmes
89673f0c0a if no tags were provided, just return 2011-04-28 09:24:02 +09:00
Damien Elmes
d611299715 make sure add/delTags() is limited to provided ids 2011-04-28 09:24:02 +09:00
Damien Elmes
e344e1a6a8 default to a useful model id on upgrade 2011-04-28 09:24:02 +09:00
Damien Elmes
13a484ea36 allow user to abort schema mod 2011-04-28 09:24:02 +09:00
Damien Elmes
2a225b1fae use the sort property set in the deck 2011-04-28 09:24:02 +09:00
Damien Elmes
d089deae5a add the ability to reverse sort order 2011-04-28 09:24:02 +09:00
Damien Elmes
efe6177c7a refactor ordering 2011-04-28 09:24:02 +09:00
Damien Elmes
a13c18cf4b start refactoring find code 2011-04-28 09:24:01 +09:00
Damien Elmes
2dfdfad6f2 update license link 2011-04-28 09:24:01 +09:00
Damien Elmes
8fcc6b3085 gpl3->agpl 2011-04-28 09:24:01 +09:00
Damien Elmes
c5e7756304 ensure model/template gid exists; mark schema modified when group deleted 2011-04-28 09:24:01 +09:00
Damien Elmes
86a7106eab when deleting a group, update cards and facts too 2011-04-28 09:24:01 +09:00
Damien Elmes
673913a2a8 fix group tree when no cards use a group 2011-04-28 09:24:01 +09:00
Damien Elmes
c682080890 make it easier to get media dir; remove tidyHTML() 2011-04-28 09:24:01 +09:00
Damien Elmes
6ed48171fc add a default group to model, add groupName() 2011-04-28 09:24:01 +09:00
Damien Elmes
c799b7c97e include model name in stdmodels; provide ability to get model outside cache 2011-04-28 09:24:01 +09:00
Damien Elmes
84d2f32685 move graph code into stats.py; remove old deck stats 2011-04-28 09:24:00 +09:00
Damien Elmes
0b92423cf7 settings->options, return bool for syncingEnabled 2011-04-28 09:24:00 +09:00
Damien Elmes
11f3de525f groupConf() takes gcid, not gid 2011-04-28 09:23:59 +09:00
Damien Elmes
692fba2ea3 use the deck's groups instead of holding on to a private copy 2011-04-28 09:23:59 +09:00
Damien Elmes
4b9c6fc822 track gcid additions too 2011-04-28 09:23:59 +09:00
Damien Elmes
f75e2af195 use a single group setting 2011-04-28 09:23:59 +09:00