feat(realtime): skip WS refetch for self-triggered events
Backend WS messages now include actor_id from the Event struct. Frontend useRealtimeSync skips the debounced refetch when the event was triggered by the current user, eliminating unnecessary re-renders of heavy components (~400ms after each user action). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c1f81427f6
commit
3e8c715de8
3 changed files with 11 additions and 4 deletions
|
|
@ -68,6 +68,11 @@ export function useRealtimeSync(ws: WSClient | null) {
|
|||
};
|
||||
|
||||
const unsubAny = ws.onAny((msg) => {
|
||||
const myUserId = useAuthStore.getState().user?.id;
|
||||
if (msg.actor_id && msg.actor_id === myUserId) {
|
||||
logger.debug("skipping self-event", msg.type);
|
||||
return;
|
||||
}
|
||||
const prefix = msg.type.split(":")[0] ?? "";
|
||||
const refresh = refreshMap[prefix];
|
||||
if (refresh) debouncedRefresh(prefix, refresh);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ export type WSEventType =
|
|||
export interface WSMessage<T = unknown> {
|
||||
type: WSEventType;
|
||||
payload: T;
|
||||
actor_id?: string;
|
||||
}
|
||||
|
||||
export interface IssueCreatedPayload {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func registerListeners(bus *events.Bus, hub *realtime.Hub) {
|
|||
if recipientID == "" {
|
||||
return
|
||||
}
|
||||
data, err := json.Marshal(map[string]any{"type": e.Type, "payload": e.Payload})
|
||||
data, err := json.Marshal(map[string]any{"type": e.Type, "payload": e.Payload, "actor_id": e.ActorID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ func registerListeners(bus *events.Bus, hub *realtime.Hub) {
|
|||
if userID == "" {
|
||||
return
|
||||
}
|
||||
data, err := json.Marshal(map[string]any{"type": e.Type, "payload": e.Payload})
|
||||
data, err := json.Marshal(map[string]any{"type": e.Type, "payload": e.Payload, "actor_id": e.ActorID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -102,8 +102,9 @@ func registerListeners(bus *events.Bus, hub *realtime.Hub) {
|
|||
}
|
||||
|
||||
msg := map[string]any{
|
||||
"type": e.Type,
|
||||
"payload": e.Payload,
|
||||
"type": e.Type,
|
||||
"payload": e.Payload,
|
||||
"actor_id": e.ActorID,
|
||||
}
|
||||
data, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue