Commit graph

118 commits

Author SHA1 Message Date
Damien Elmes
32fde2a072 encode daily steps in left
When a user has learning steps that extend past the daily cutoff, we end up
counting them all instead of only the ones that would be done today. In order
to avoid this without expensive calculations or db schema changes, we
calculate the number of steps until the daily cutoff and pack it into the left
column, as totalLeft + leftToday*1000.
2012-05-20 16:05:50 +09:00
Damien Elmes
a15b210349 be tolerant of bad upgrade 2012-05-19 08:23:11 +09:00
Damien Elmes
9aedb4a5e0 don't allow empty files in media folder 2012-05-16 05:35:58 +09:00
Damien Elmes
1394b80152 catch attempt to set invalid due date on cards 2012-05-14 05:48:20 +09:00
Damien Elmes
b2580a9a15 fix odue issue 2012-05-08 02:11:40 +09:00
Damien Elmes
1a80ffa8a2 shared css 2012-05-06 20:04:28 +09:00
Damien Elmes
461e240d53 allow python-bundled json 2012-04-28 17:41:56 +09:00
Damien Elmes
ae3e775fdd upgrade decks to fix odue bug 2012-04-22 07:17:06 +09:00
Damien Elmes
fe0e227325 don't upgrade clozes while iterating 2012-04-19 09:58:12 +09:00
Damien Elmes
5cbe93b63d more cloze work
- upgrade old decks
- specify the field in the cloze, so the user can have an id in the first
  field
2012-04-19 08:32:19 +09:00
Damien Elmes
41fa9a9896 cloze refactor wip 2012-04-19 07:14:03 +09:00
Damien Elmes
b35b105750 don't clobber decks on upgrade 2012-03-13 23:18:45 +09:00
Damien Elmes
b9cc9bf0b2 deck upgrade 2012-03-12 13:49:32 +09:00
Damien Elmes
f6b2e69669 remove did from notes, use model did instead 2012-03-09 09:12:27 +09:00
Damien Elmes
a2312f9a1f change cards table schema
In preparation for cramming:

- add odid for storing old deck on a per-card basis
- rename edue to odue
- at the moment note.did still exists, but in the future we may ignore it and
  use model.did instead
2012-03-08 11:28:12 +09:00
Damien Elmes
3823151d6f make sure changes during upgrade don't have side effects 2012-02-24 22:29:04 +09:00
Damien Elmes
00becd01eb add async flag 2011-12-13 12:15:32 +09:00
Damien Elmes
8ede57b024 should init schema on collection creation 2011-12-13 09:33:11 +09:00
Damien Elmes
451962d4a8 drop the special config for top level decks
New/rev card mixing, collapse time and the timeboxing limit are now a
collection property. I appreciate how it could be useful to have those
settings per top-level deck in some cases, but having some settings inherited
from the top level deck makes for a confusing UI.
2011-12-09 07:55:40 +09:00
Damien Elmes
594204a134 queue argument is obsolete 2011-12-06 00:05:14 +09:00
Damien Elmes
b99dbb1466 don't .reset() on deck load by default anymore 2011-12-05 13:40:37 +09:00
Damien Elmes
92352d4725 convert guid to base 91 string
Because JSON doesn't support 64 bit numbers, we need to either convert the 64
bit numbers to a string during transport, or store the ids as a string. At
base 91 a 64 bit number only takes an extra two bytes, and it means we can
dump DB results directly into JSON without having to apply any transformation.
2011-12-03 14:25:18 +09:00
Damien Elmes
1db4b41e23 use WAL mode if available; don't delete media in check 2011-12-02 22:44:00 +09:00
Damien Elmes
b5c0b1f2c7 drop required/unique field properties
Instead of having required and unique flags for every field, enforce both
requirements on the first field, and neither on the rest. This mirrors the
subject/body format people are used to in note-taking apps. The subject
defines the object being learnt, and the remaining fields represent properties
of that object.

In the past, duplicate checking served two purposes: it quickly notified the
user that they're entering the same fact twice, and it notified the user if
they'd accidentally mistyped a secondary field. The former behaviour is
important for avoiding wasted effort, and so it should be done in real time.
The latter behaviour is not essential however - a typo is not wasted effort,
and it could be fixed in a periodic 'find duplicates' function. Given that
some users ended up with sluggish decks due to the overhead a large number of
facts * a large number of unique fields caused, this seems like a change for
the better.

This also means Anki will let you add notes as long as as the first field has
been filled out. Again, this is not a big deal: Anki is still checking to make
sure one or more cards will be generated, and the user can easily add any
missing fields later.

As a bonus, this change simplifies field configuration somewhat. As the card
layout and field dialogs are a popular point of confusion, the more they can
be simplified, the better.
2011-11-24 22:16:03 +09:00
Damien Elmes
f7790275ce groups -> decks 2011-11-23 19:28:09 +09:00
Damien Elmes
279a942642 deck -> collection 2011-11-23 17:47:44 +09:00
Damien Elmes
6e4e8249fb facts -> notes 2011-11-23 12:37:21 +09:00
Damien Elmes
76960abd75 fix upgrading; drop old mnemosyne 1 importer 2011-10-20 22:05:34 +09:00
Damien Elmes
cf4abcb403 split upgrade code into separate file; use .anki2 now 2011-10-20 05:26:50 +09:00
Damien Elmes
9fdfac722d fixed bug in bundling 2011-09-24 14:46:42 +09:00
Damien Elmes
667b89ecc5 support partial syncs of arbitrary size
The full sync threshold was a hack to ensure we synced the deck in a
memory-efficient way if there was a lot of data to send. The problem is that
it's not easy for the user to predict how many changes there are, and so it
might come as a surprise to them when a sync suddenly switches to a full sync.

In order to be able to send changes in chunks rather than all at once, some
changes had to be made:

- Clients now set usn=-1 when they modify an object, which allows us to
  distinguish between objects that have been modified on the server, and ones
  that have been modified on the client. If we don't do this, we would have to
  buffer the local changes in a temporary location before adding the server
  changes.
- Before a client sends the objects to the server, it changes the usn to
  maxUsn both in the payload and the local storage.
- We do deletions at the start
- To determine which card or fact is newer, we have to fetch the modification
  time of the local version. We do this in batches rather than try to load the
  entire list in memory.
2011-09-24 12:42:02 +09:00
Damien Elmes
e8f1cecd81 don't allow loading of decks created with future versions 2011-09-24 07:30:34 +09:00
Damien Elmes
a98126dab4 on upgrade make sure we set left 2011-09-23 10:31:31 +09:00
Damien Elmes
e7f416406d refactor learning
Rather than showing the user how many cards are in the learning queue, we want
to be able to show them the number of reps they have to do to clear the queue,
so they can better estimate the required time. Before we were counting up with
the grade column, but this means we can't quickly sum up the number of reps
left. So we invert it, and count down instead.

I also dropped the 'first time bonus' for now. If there's enough demand for
it, it can be added back by using the flags column, instead of a dedicated
cycles column.
2011-09-23 10:29:49 +09:00
Damien Elmes
2b34d8a948 more group/sched refactoring
- keep track of rep/time counts per group, instead of just at the top level
- sort by due after retrieving learn cards
- ensure activeGroups is sorted alphabetically
- ensure new cards come in alphabetical group order
- ensure queues are refilled when empty
2011-09-23 08:19:22 +09:00
Damien Elmes
024c42fef8 group scheduling refactor
see the following for background discussion:
http://groups.google.com/group/ankisrs-users/browse_thread/thread/4db5e82f7dff74fb

- change sched index to the more efficient gid, queue, due
- drop the dynamic index support. as there's no no q/a cache anymore, it's
  cheap enough to hit the cards table directly, and we can't use the index in
  its new form.
- drop order by clauses (see todo)
- ensure there's always an active group. if users want to study all groups at
  once, they need to create a top level group. we do this because otherwise
  the 'top level group' that's active when everything is selected is not
  clear.

to do:

- new cards will appear in gid order, but the gid numbers don't reflect
  alphabetical sorting. we need to change the scheduling code so that it steps
  through each group in turn
- likewise for the learn queue
2011-09-22 11:54:01 +09:00
Damien Elmes
3e5041f337 reduce default cache size
Use a more conservative 40MB for systems with a smaller amount of memory.
Ideally we should bump this up if we detect the running system has a decent
amount of memory.
2011-09-18 05:07:30 +09:00
Damien Elmes
2e628996a3 add flags back to cards, and fix syncing 2011-09-18 04:37:48 +09:00
Damien Elmes
f32787c18e add guid and flags to facts
Syncing and shared decks have conflicting priorities:

- For syncing, we need to ensure that the deck remains in a consistent state.
  In the past, Anki allowed deletions to be overriden by a more recently
  modified object, but this could lead to a broken deck in certain
  circumstances. For example, if a user deletes a fact (and its cards) on one
  side, but does something to bump a card's mod time on another side, then
  when syncing the card would be brought back to life without its fact. Short
  of complex code to check all the relations, we're limited to two options:
  forcing a full sync when things are deleted, or ensuring objects can't come
  back to life.

- When facts are shared between people, we need a way to identify if two facts
  arose from the same source. We can't compare based on content, as the
  content may have changed partially or completely. And we can't use the
  timestamp ids because of the above restriction on bringing objects back to
  life. If we did that, people could download a shared deck, decide they don't
  want it, and delete it. When they later decide to add it again, it wouldn't
  be possible: either nothing would be imported because of the old graves, or
  the ids would have to be rewritten. If we do the latter, the facts are no
  longer associated with each other, and we lose the ability to update the
  deck.

So we need to give facts two IDs: one used as the primary key and for syncing,
and another 'global id' for importing/sharing. I used a 64 bit random number,
because a) it's what Anki's used in the past, so by reusing the old IDs we
don't break existing associations on upgrade, and b) it's a decent compromise
between the possibility of conflicts and performance.

Also re-added a flags column to the facts. The 'data' column is intended to
store JSON in the future for extra features without changing the schema, but
that's slow for simple state checks. Flags will be used as a bitmask.
2011-09-18 04:31:53 +09:00
Damien Elmes
bc9f6e6a24 add USNs
Decks now have an "update sequence number". All objects also have a USN, which
is set to the deck USN each time they are modified. When syncing, each side
sends any objects with a USN >= clientUSN. When objects are copied via sync,
they have their USNs bumped to the current serverUSN. After a sync, the USN on
both sides is set to serverUSN + 1.

This solves the failing three way test, ensures we receive all changes
regardless of clock drift, and as the revlog also has a USN now, ensures that
old revlog entries are imported properly too.

Objects retain a separate modification time, which is used for conflict
resolution, deck subscriptions/importing, and info for the user.

Note that if the clock is too far off, it will still cause confusion for
users, as the due counts may be different depending on the time. For this
reason it's probably a good idea to keep a limit on how far the clock can
deviate.

We still keep track of the last sync time, but only so we can determine if the
schema has changed since the last sync.

The media code needs to be updated to use USNs too.
2011-09-13 21:10:21 +09:00
Damien Elmes
9aad5c1166 more unit tests, fix bugs
- make sure gconf has an id
- merge deck conf
2011-09-09 22:34:50 +09:00
Damien Elmes
7034c1ed29 drop syncName, fix leech unit test 2011-09-07 20:11:26 +09:00
Damien Elmes
de8a5b69ed top level groups
As discussed on the forums, moving to a single collection requires moving some
deck-level configuration into groups so users can have different settings like
new cards/day for each top level item.

Also:
- store id in groups
- add mod time to gconf updates
- move the limiting code that's not specific to scheduling into groups.py
- store the current model id per top level group
2011-09-07 01:31:46 +09:00
Damien Elmes
5179d82f7f drop the sources table; we'll store it in deck conf 2011-09-06 23:24:51 +09:00
Damien Elmes
9130e09b3e rename some columns for consistency
- revlog's 'time' is now 'id', like the other tables
- 'taken' is now 'time'
- also dropped the eta code
2011-09-06 21:33:19 +09:00
Damien Elmes
b3937a3280 make sure currentModelId is set and css regenerated on upgrade 2011-08-28 15:14:04 +09:00
Damien Elmes
6a00419ebc merge deck.qconf and deck.conf 2011-08-28 14:17:33 +09:00
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
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