Commit graph

193 commits

Author SHA1 Message Date
Damien Elmes
fabec6e920 more sync resuming changes
The server now returns the next usn after every addFiles(), so an interrupted
upload doesn't cause the uploaded material to be sent back down.
2011-12-06 23:04:26 +09:00
Damien Elmes
be66c960a9 rework media syncing so we can resume 2011-12-06 22:18:41 +09:00
Damien Elmes
c0edcae238 fix some sync bugs
- don't send server graves graves back on the next sync
- make sure we update usns of models/tags/decks as well on upload
- don't die when updating decks after current deck deleted
- report counts when sanity check fails
2011-12-06 01:35:54 +09:00
Damien Elmes
4a88885e83 default to compression level 6 2011-12-06 00:05:39 +09:00
Damien Elmes
8308c79fa6 minor refactor of count handling
- drop lrnCount; rename lrnRepCount to lrnCount
- on card fetch, decr count by card.left
- drop cardCounts(), rename repCounts() to just counts()
- fix lrn count bugs
2011-12-05 19:15:46 +09:00
Damien Elmes
41636f41f8 tweak sync error handling 2011-12-05 17:44:54 +09:00
Damien Elmes
0395047579 initial usn is 0, so distinguish between 0 and false 2011-12-05 15:27:06 +09:00
Damien Elmes
b33c2e99c0 return false, not 'continue', when not finished 2011-12-05 14:43:32 +09:00
Damien Elmes
1ec747dbb4 tweak sync hooks 2011-12-04 15:56:38 +09:00
Damien Elmes
6bad4cc8c2 fix sanity check 2011-12-04 15:23:43 +09:00
Damien Elmes
9d5357f7a6 after a save, revert to unmodified state; sync tweaks 2011-12-04 14:56:12 +09:00
Damien Elmes
8fff05618c check download before overwrite 2011-12-03 22:15:36 +09:00
Damien Elmes
6965a9c102 sync tweaks 2011-12-03 21:06:27 +09:00
Damien Elmes
d148a6cf1b bundle ssl certs; share con across all sync types 2011-12-03 16:38:45 +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
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
c6c6af4328 split remote sync tests into separate file 2011-11-07 16:21:29 +09:00
Damien Elmes
0c85acf3f7 refactor to support early exit when no media changes
- regular sync now receives a media USN as well
- server bumps media usn not only on sync but any other media change
- added local media.hasChanged()
2011-10-06 15:34:22 +09:00
Damien Elmes
b4fdf1c690 send 'continue' for multiple zips; test splitting 2011-10-06 13:51:44 +09:00
Damien Elmes
8c1f397459 ensure successive calls work 2011-10-06 13:25:01 +09:00
Damien Elmes
0a52f55e50 test removing too 2011-10-06 13:06:32 +09:00
Damien Elmes
eca6ef204f check file is added on remote test 2011-10-03 13:42:53 +09:00
Damien Elmes
49181ee738 fix media zipping and addFiles call 2011-10-03 12:59:35 +09:00
Damien Elmes
5da3bba1df initial work on media syncing 2011-10-03 12:45:08 +09:00
Damien Elmes
a8d2578be5 move common auth+upload code into base class 2011-10-01 22:16:56 +09:00
Damien Elmes
bf3bb9dd32 if sync server offline, abort sync tests 2011-10-01 20:44:35 +09:00
Damien Elmes
f131021c7e remote partial syncing working; fixed mod time on finish() 2011-10-01 14:24:39 +09:00
Damien Elmes
dd5b2056fb factor out file uploads; use for incremental sync too 2011-09-30 21:09:10 +09:00
Damien Elmes
20d753591d add timestamp & common error checks to meta(); kill old code 2011-09-29 22:18:36 +09:00
Damien Elmes
aabc884341 start work on remote syncing; full up/down implemented 2011-09-29 20:58:42 +09:00
Damien Elmes
22df2790f9 refactor media change logging 2011-09-25 06:33:57 +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
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
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
ee767ff132 refactor to allow group deletions without schema mod
because group deletions are likely to be a semi-common operation (esp. for new users trying out shared material), deleting groups will no longer cause a full sync. in order to avoid syncing issues, we now allow cards/facts/etc to point to an invalid group, and in that case, we just treat them like they're in the default group
2011-09-15 01:37:30 +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
cf8288a5e0 todo 2011-09-09 23:06:12 +09:00
Damien Elmes
14b642f633 mod schema when rev order updated 2011-09-09 22:38:00 +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
f15cb23c41 skip the 600 second pad during testing 2011-09-09 21:17:42 +09:00
Damien Elmes
85a2bb6193 revlog timestamp is ms based; should fetch facts/cards by mod not id 2011-09-09 21:11:11 +09:00
Damien Elmes
362ae3eee2 initial work on sync refactor
Ported the sync code to the latest libanki structure. Key points:

No summary:

The old style got each side to fetch ids+mod times and required the client to
diff them and then request or bundle up the appropriate objects. Instead, we now
get each side to send all changed objects, and it's the responsibility of the
other side to decide what needs to be merged and what needs to be discarded.
This allows us to skip a separate summary step, which saves scanning tables
twice, and allows us to reduce server requests from 4 to 3.

Schema changes:

Certain operations that are difficult to merge (such as changing the number of
fields in a model, or deleting models or groups) result in a full sync. The
user is warned about it in the GUI before such schema-changing operations
execute.

Sync size:

For now, we don't try to deal with large incremental syncs. Because the cards,
facts and revlog can be large in memory (hundreds of megabytes in some cases),
they would have to be chunked for the benefit of devices with a low amount of
memory.

Currently findChanges() uses the full fact/card objects which we're planning to
send to the server. It could be rewritten to fetch a summary (just the id, mod
& rep columns) which would save some memory, and then compare against blocks
of a few hundred remote objects at a time. However, it's a bit more
complicated than that:

- If the local summary is huge it could exceed memory limits. Without a local
  summary we'd have to query the db for each record, which could be a lot
  slower.

- We currently accumulate a list of remote records we need to add locally.
  This list also has the potential to get too big. We would need to
  periodically commit the changes as we accumulate them.

- Merging a large amount of changes is also potentially slow on mobile
  devices.

Given the fact that certain schema-changing operations require a full sync
anyway, I think it's probably best to concentrate on a chunked full sync for
now instead, as provided the user syncs periodically it should not be easy to
hit the full sync limits except after bulk editing operations.

Chunked partial syncing should be possible to add in the future without any
changes to the deck format.

Still to do:
- deck conf merging
- full syncing
- new http proxy
2011-09-08 12:50:42 +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
a9b4285959 rename a few methods for consistency 2011-08-28 13:48:17 +09:00
Damien Elmes
91efb8f30b some initial sync work 2011-05-29 08:13:54 +09:00