-
Notifications
You must be signed in to change notification settings - Fork 13
Description
In kinto.js, to build snapshot of collection at timestamp T we do:
- check that the history is complete (the collection creation entry is available)
- fetch the whole history of records changes for the collection
- start from the collection creation
- apply all history steps until timestamp=T
This is inefficient, especially for old collections, mainly because we often want to compute a snapshot of a recent timestamp.
Why do we do this? Because the history entries contain the current version of the object, not the previous. Therefore entries related to deletion contain tombstones and not the deleted object. In order to obtain the deleted object attributes, we have to get its last update or its creation.
There should be more efficient ways.
For example, we could introduce a new endpoint and do it server-side where queries on the database are more efficient.
Or, find a smarter algorithm on the client, for example:
- fetch the collection content since timestamp=T. This will give us the list of records that were either created or changed or deleted since T.
- fetch the history entries related to these record ids where action is create or update, prior to timestamp<T
- use the most recent one of each entry to get the record attributes before it was deleted or modified
If the list of objects at step 1 is too big, then use the previous method.
In most cases, there should be less than a few dozens of records to inspect, because collections that contains many records are not manipulated by humans, and users won't compare with very old timestamps where a lot of records were modified.