Commit graph

38 commits

Author SHA1 Message Date
Damien Elmes
c1ea82273b log actual changes, not all prospectives 2012-05-06 17:53:18 +09:00
Damien Elmes
cdffab235c add option to dump db args 2012-04-21 08:57:08 +09:00
Damien Elmes
a697c292b5 when echo on, log call time too 2011-12-13 12:14:36 +09:00
Damien Elmes
cdb33cf6a8 don't bump mod time unless the db has actually been changed 2011-12-04 13:51:13 +09:00
Damien Elmes
457ee809f4 don't implicitly commit in context manager 2011-12-04 13:00:24 +09:00
Damien Elmes
5da3bba1df initial work on media syncing 2011-10-03 12:45:08 +09:00
Damien Elmes
9b8e949a72 add db timeout 2011-09-29 15:57:29 +09:00
Damien Elmes
786600ebb6 check python version and locale on load 2011-04-28 09:24:03 +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
ba09529e34 speed up the revlog migration, tweak db handling
remove the unnecessary transaction magic; we just needed to make sure to
lock again after undo is initialized
2011-04-28 09:23:55 +09:00
Damien Elmes
9226922af8 properly lock the DB 2011-04-28 09:23:55 +09:00
Damien Elmes
511d6e89a1 remove progress handling code; we'll do it in the GUI or provide cb 2011-04-28 09:23:55 +09:00
Damien Elmes
174b13f7df speed up new card fetching, add a text factory arg to the db, fix stopMplayer() 2011-04-28 09:23:55 +09:00
Damien Elmes
f74d9b68fe trigger the db progress handler after more operations
We originally were triggering on 100 opcodes, because at the time we were
doing write-heavy alterations to the DB for inactive tags, and a higher level
of opcodes would pause the interface for a long time. The query structure is
different now, so we can afford to save the overhead of more frequent calls.

With the change, a .reset() triggers the handler 3 times; fixIntegrity()
triggers it 30 times over a period of 4.5 seconds.
2011-04-28 09:23:55 +09:00
Damien Elmes
59754eacb2 improve id upgrade speed by a factor of 5 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
8a60ee0794 initial changes to models, deck, etc
- move most scheduling parameters from deck to models
- remove obsolete fields in deck and models
- decks->deck
- remove deck id reference in models
- move some deckVars into the deck table
- simplify deckstorage
- lock sessionhelper by default
- add models/currentModel as properties instead of ORM mappings
- remove models.tags
- remove remaining support for memory-backed databases
- use a blank string for syncName instead of null
- remove backup code; will handle in gui
- bump version to 100
- update unit tests
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
f03000d27b remove string exceptions for python2.6 2010-06-10 13:24:46 +09:00
Damien Elmes
f69d946f83 more sqlalchemy compat 2010-05-02 16:15:32 +09:00
Damien Elmes
a1d3f13f0a update for sqlalchemy 0.6 2010-04-21 13:21:16 +09:00
Damien Elmes
d44cbd5518 remove logging hack 2009-11-30 08:11:34 +09:00
Damien Elmes
d02c1fb70a add nullpool to db, crop newlines in logs 2009-09-21 20:41:58 +09:00
Damien Elmes
0bf59fa00b make sure to close cursor for first() 2009-03-21 03:50:43 +09:00
Damien Elmes
95b8d655e6 remove shared cache mode, it's not needed 2009-03-18 22:45:43 +09:00
Damien Elmes
e4354181c4 db progress handler, work on tag cache 2009-02-19 16:01:04 +09:00
Damien Elmes
2a0f22348d ignore sqlalchemy 0.5 deprecation warnings for now 2009-01-21 18:36:58 +09:00
Damien Elmes
93332079b5 add model copy support 2009-01-14 15:28:27 +09:00
Damien Elmes
4b6dcf6f6c fix db.py for ankiweb 2009-01-08 11:18:38 +09:00
Damien Elmes
7c764763d2 sqlalchemy 0.5 compat 2009-01-07 11:37:01 +09:00
Damien Elmes
8f983d5bcc always keep as unicode 2008-11-21 23:41:14 +09:00
Damien Elmes
97cf06b333 don't fail on old sqlalchemy 2008-11-15 17:45:57 +09:00
Damien Elmes
a3d968cd55 add primary key constraint support 2008-11-14 22:49:18 +09:00
Damien Elmes
91114a72c5 no tag searching, add index to db.py 2008-11-14 19:48:47 +09:00
Damien Elmes
793b660ec3 dump location of non-unicode string references 2008-11-14 13:50:51 +09:00
Damien Elmes
b2d0e5d3df wip 2008-11-07 18:44:49 +09:00
Damien Elmes
5da3a0f5d3 initial commit from hg 2008-09-27 23:50:03 +09:00