andymatuschak / orbit

Experimental spaced repetition platform for exploring ideas in memory augmentation and programmable attention
https://withorbit.com
Other
1.71k stars 54 forks source link

Adopting modifyEntities in Database, implementing incremental snapshot updating #227

Closed andymatuschak closed 3 years ago

andymatuschak commented 3 years ago

@kirkbyo, I'd be grateful for your eyes on this change, since it involved some plumbing in IDBDatabaseBackend.

At a high level, I'm doing two things here (sorry to have combined them into a single commit—it was a bit tangled):

  1. Adopting modifyEntities in Database.putEvents, rather than getEntities followed by putEntities.
  2. Implementing a "fast path" for the common case of updating an entity snapshot, in which the new events can be applied directly on top of the previous snapshot.

To accomplish this, I had to add a "column" to the backends, and I also had to change modifyEntities's API signature to use general types, rather than Dexie-specific types.

While implementing this, I noticed (thanks, failing tests!) that IDBDatabaseBackend.modifyEntities actually only supported updating pre-existing entities, but not inserting new ones. I fixed that up too.

andymatuschak commented 3 years ago

(ignore the test failures—I've implemented SQLDatabaseBackend.modifyEntities in a later commit, but wanted to avoid making this PR too big)