atomic-server icon indicating copy to clipboard operation
atomic-server copied to clipboard

Sync collections: send updates of query results using CommitMonitor

Open joepio opened this issue 2 years ago • 0 comments

I'd like Collections to update live. The server is keeping track of which user has which Collection opened, and it knows every Commit and updated Atom that crosses it.

Some thoughts:

  • use it to cache collections as resources. This can also be used to make Collections index time by default, so we don't even have to run the query, and we can actually sort collections by member count, for example. Although this would not work with authorized results, as the counts may differ per user.
  • We need to be aware that Collections are actually different for each user, which means we have to authorize every single member inside of it when it updates. Maybe that is something that needs to change - we could add the user to the collection scope, or maybe use some Grant.

Invalidate approach

The server sends invalidate Commits (which do not exist yet) to the Clients, and clients have to re-fetch collections if it is relevant

  • Agent Anne is subscribed to Collection
  • Agent Alex adds an item to the Collection, sends a Commit to the server
  • Server validates Commit, and updates the indexes. It encounters the relevant QueryFilter as it iterates over the watched_queries items. We currently do not use the value in the KV pair, but we could store relevant Collections in the values. Now, we know which collections need to be invalidated.
  • The server sends an invalidate Commit to all listeners, who then GET the Collection again.

Some thoughts with this approach:

  • How do we prevent the invalidate command to be sent far too often? We only need it if something either enters or leaves somewhere. Maybe we store the Count and check if that has changed? I don't know.

Use tables, require parent

A radically different approach: only allow real-time sync in Tables, similar to how ChatRooms work. When a child (i.e. an item that has the Table as its parent) is created, we send a Commit to all listeners of the Table.

Seems easier, right?

joepio avatar Aug 20 '22 15:08 joepio