Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send diffs for presence #658

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Send diffs for presence #658

wants to merge 4 commits into from

Conversation

tonsky
Copy link
Contributor

@tonsky tonsky commented Dec 24, 2024

WIP

@tonsky tonsky self-assigned this Dec 24, 2024
Copy link

View Vercel preview at instant-www-js-presence-diffs-jsv.vercel.app.

@tonsky
Copy link
Contributor Author

tonsky commented Dec 27, 2024

Main functionality is working. Two more things:

  • I do want to build a demo that logs everything so I can check that what I think is happening is actually happening
  • Clean up old in-memory impl (might be a separate PR)

@tonsky tonsky marked this pull request as ready for review December 27, 2024 19:11
(handle-event store-conn event)))
(defn init-hz
([store-conn]
(init-hz {}))
Copy link
Contributor

@stopachka stopachka Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming here we want to do init-hz store-conn {} 🫡

(conj entries-to-process last-entry)))

(defn straight-jacket-process-receive-q-batch [store-conn eph-store-atom batch metadata]
(defmulti consolidate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

@@ -460,7 +460,11 @@ export default class Reactor {
break;
case "refresh-presence":
const roomId = msg["room-id"];
this._setPresencePeers(roomId, msg.data);
if (msg["edits"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue I realize: what happens to old clients?

As it stands, I think if the client doesn't upgrade their version of the client SDK, they won't be able to handle the new refresh-presence events from the server.


Potential solution:

Clients currently send a versions map when they init:

https://github.com/instantdb/instant/blob/main/client/packages/core/src/Reactor.js#L1056

This would be the first time we use it, but perhaps what we can do is:

  1. We detect if the client is on a version of Instant > x
  2. In that case, we start sending the refresh-presence events with edits in them.
    a. Aside, perhaps we send different kinds of events too -- something like reset-presence and 'patch-presence', to keep the paths separate, but I don't feel strongly about this idea

What do you think?

{:keys [session-ids last-data]} (get-in @room-maps [:rooms room-key])]
(when (seq session-ids)
(let [room-data (.get (get-hz-rooms-map) room-key)
edits (when last-data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One rough thought I had:

Is it necessary to derive edits? Perhaps we could broadcast set-presence events similar, to how we broadcast server-broadcast events.

This would mean our resolution would be a bit less granular, but we wouldn't have to do a calculation to derive the edits.


This could be something we layer on down the road though, as am open to either solution.

Copy link
Contributor

@stopachka stopachka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Main comment was about handling backwards-compatibility. Rest looks good to me, but deferring to @dwwoelfel's look, as he is the hazelcast expert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants