Commit graph

55 commits

Author SHA1 Message Date
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
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
cfd4198503 add call to determine number of buttons to show; 2.5m -> 2.5mo 2011-04-28 09:23:57 +09:00
Damien Elmes
8705085200 update latex support 2011-04-28 09:23:56 +09:00
Damien Elmes
908dccc2c0 implement new review code, add unit tests
Instead of the old approach to sibling spacing, we instead try to pick a due
date that doesn't have any siblings.
2011-04-28 09:23:56 +09:00
Damien Elmes
e728d49232 delete -> del for consistency 2011-04-28 09:23:55 +09:00
Damien Elmes
f5b326c753 more checksum work
- convert checksums to int
- add bulk update & update on upgrade
- add indices pending performance testing. The fsum table & indices add about
  2MB to a deck with 50k unique fields
2011-04-28 09:23:54 +09:00
Damien Elmes
4becd8399c implement field cache, fix unit tests, remove some importers
the field cache (fsums table) also needs to store the model id to preserve the
old behaviour of limiting duplicate checks to a given model, and to ensure
we're actually comparing against the same fields

removed the dingsbums and wcu importers; will accept them back if the authors
port them to the new codebase.
2011-04-28 09:23:54 +09:00
Damien Elmes
9c247f45bd remove q/a cache, tags in fields, rewrite remaining ids, more
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.
2011-04-28 09:23:53 +09:00
Damien Elmes
3cb4ade4a1 simplify bold/italic/underline tags from qt in upgrade 2011-04-28 09:23:53 +09:00
Damien Elmes
2f27133705 drop sqlalchemy; massive refactor
SQLAlchemy is a great tool, but it wasn't a great fit for Anki:
- We often had to drop down to raw SQL for performance reasons.
- The DB cursors and results were wrapped, which incurred a
  sizable performance hit due to introspection. Operations like fetching 50k
  records from a hot cache were taking more than twice as long to complete.
- We take advantage of sqlite-specific features, so SQL language abstraction
  is useless to us.
- The anki schema is quite small, so manually saving and loading objects is
  not a big burden.

In the process of porting to DBAPI, I've refactored the database schema:
- App configuration data that we don't need in joins or bulk updates has been
  moved into JSON objects. This simplifies serializing, and means we won't
  need DB schema changes to store extra options in the future. This change
  obsoletes the deckVars table.
- Renamed tables:
-- fieldModels -> fields
-- cardModels -> templates
-- fields -> fdata
- a number of attribute names have been shortened

Classes like Card, Fact & Model remain. They maintain a reference to the deck.
To write their state to the DB, call .flush().

Objects no longer have their modification time manually updated. Instead, the
modification time is updated when they are flushed. This also applies to the
deck.

Decks will now save on close, because various operations that were done at
deck load will be moved into deck close instead. Operations like undoing
buried card are cheap on a hot cache, but expensive on startup.
Programmatically you can call .close(save=False) to avoid a save and a
modification bump. This will be useful for generating due counts.

Because of the new saving behaviour, the save and save as options will be
removed from the GUI in the future.

The q/a cache and field cache generating has been centralized. Facts will
automatically rebuild the cache on flush; models can do so with
model.updateCache().

Media handling has also been reworked. It has moved into a MediaRegistry
object, which the deck holds. Refcounting has been dropped - it meant we had
to compare old and new value every time facts or models were changed, and
existed for the sole purpose of not showing errors on a missing media
download. Instead we just media.registerText(q+a) when it's updated. The
download function will be expanded to ask the user if they want to continue
after a certain number of files have failed to download, which should be an
adequate alternative. And we now add the file into the media DB when it's
copied to th emedia directory, not when the card is commited. This fixes
duplicates a user would get if they added the same media to a card twice
without adding the card.

The old DeckStorage object had its upgrade code split in a previous commit;
the opening and upgrading code has been merged back together, and put in a
separate storage.py file. The correct way to open a deck now is import anki; d
= anki.Deck(path).

deck.getCard() -> deck.sched.getCard()
same with answerCard
deck.getCard(id) returns a Card object now.

And the DB wrapper has had a few changes:
- sql statements are a more standard DBAPI:
 - statement() -> execute()
 - statements() -> executemany()
- called like execute(sql, 1, 2, 3) or execute(sql, a=1, b=2, c=3)
- column0 -> list
2011-04-28 09:23:53 +09:00
Damien Elmes
1d6dbf9900 rework tag handling and remove cardTags
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.
2011-04-28 09:23:29 +09:00
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
Damien Elmes
9421a037f6 remove self explanatory module docstrings; strip trailing whitespace 2011-04-28 09:21:07 +09:00
Damien Elmes
4302306fe9 use a checksum for field values; fixed import->update number
Previously we had an index on the value field, which was very expensive for
long fields. Instead we use a separate column and take the first 8 characters
of the field value's md5sum, and index that. In decks with lots of text in
fields, it can cut the deck size by 30% or more, and many decks improve by
10-20%. Decks with only a few characters in fields may increase in size
slightly, but this is offset by the fact that we only generate a checksum for
fields that have uniqueness checking on.

Also, fixed import->update reporting the total # of available facts instead of
the number of facts that were imported.
2011-04-28 09:21:06 +09:00
Damien Elmes
b426ad4271 fix html comments in translator's patch 2011-02-01 18:57:44 +09:00
Damien Elmes
6071f8e209 include latex in alt tags of generated image 2011-01-26 13:01:12 +09:00
Damien Elmes
29a53b268f strip qt's rtl marker 2011-01-14 00:31:07 +09:00
Damien Elmes
4d2d9eab81 generate latex at fact modification, not review
- latex now slots in to the formatQA hook to render images in the q/a
- moved call() to utils
- cache/uncache latex have been obsoleted. User can delete manually, and
  images will be regenerated with a DB check
2010-12-11 01:40:49 +09:00
Damien Elmes
84b99b1ae5 don't allow tags to be prefixed with a colon, as this breaks sqlite 2010-11-26 03:49:01 +09:00
Damien Elmes
34d6efe1df marcus: handle html entities properly when stripping html 2010-10-27 20:12:00 +09:00
Damien Elmes
8ce0ff5b8b add a field cache for searching without html 2010-10-27 19:00:49 +09:00
Damien Elmes
ea3bf14019 if using no points of precision, take the floor 2010-10-26 12:54:58 +09:00
Damien Elmes
27694adf1a patch from Chris Burel, fix qt html rewriting on 4.6.1+ 2010-02-23 17:25:12 +09:00
Damien Elmes
ec263d0d63 if there is a period, always use the plural 2010-01-29 20:05:04 +09:00
Damien Elmes
9172c9b697 remove obsolete time span pair code 2010-01-29 19:28:38 +09:00
Damien Elmes
52be4b059d make short times i18n 2009-08-17 06:52:14 +09:00
Damien Elmes
a478e9af6b apply translation patch from piotr 2009-06-16 02:23:56 +09:00
Damien Elmes
d7961413b4 make sure to set card model id when creating cards, tweak code formatting 2009-06-06 01:09:08 +09:00
Damien Elmes
b136e505b0 strip <style> tags as well 2009-06-04 07:07:49 +09:00
Damien Elmes
4b3532f3eb on python2.4, fall back to non-localized strings 2009-03-29 03:52:49 +09:00
Susanna Björverud
f4adc657bd Added fmtFloat def 2009-03-25 11:20:42 +01:00
Susanna Björverud
dfb477ec4b new def to format percentages with current locale decimal point 2009-03-25 11:02:50 +09:00
Damien Elmes
eed5df1038 use format_string() 2009-03-24 09:05:35 +09:00
Damien Elmes
9fba248489 fix locale.format location 2009-03-24 08:52:53 +09:00
Damien Elmes
1648d254d6 format decimals using locale 2009-03-24 08:38:29 +09:00
Damien Elmes
1098bb1c5c make fmtTimeSpan strings translatable 2009-03-23 10:48:28 +09:00
Damien Elmes
d127ae4175 separate tags with spaces 2009-02-08 03:13:37 +09:00
Damien Elmes
6ce63b4889 fix plural definition 2009-01-04 11:57:41 +09:00
Damien Elmes
feb0acf52c don't remove leading/trailing whitespace 2008-12-23 18:39:14 +09:00
Damien Elmes
6434d5c03e don't collapse multiple spaces 2008-12-23 18:38:54 +09:00
Damien Elmes
21b59408cd refactor features to use hooks, update stdmodels, update findTags()
- remove description from fields, cards and models
- remove features and use field names instead
2008-12-03 19:22:15 +09:00
Damien Elmes
cd64b0db9e add user tags list, sort tags in canonify 2008-11-28 18:53:04 +09:00
Damien Elmes
8f983d5bcc always keep as unicode 2008-11-21 23:41:14 +09:00
Damien Elmes
90487d86ad remove obsolete code 2008-11-21 20:24:23 +09:00
Damien Elmes
c4d30a20d9 remove mergeTags() 2008-11-21 00:22:23 +09:00
Damien Elmes
b2d0e5d3df wip 2008-11-07 18:44:49 +09:00
Damien Elmes
c130dac060 temporarily disable history, add canonifyTags 2008-10-19 18:46:05 +09:00