mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 12:32:00 +08:00
Merge pull request #4819 from toeverything/61/hotfix
fix(server): remove awareness states cache
This commit is contained in:
@@ -2,6 +2,7 @@ import { registerEnumType } from '@nestjs/graphql';
|
|||||||
|
|
||||||
export enum DocVariant {
|
export enum DocVariant {
|
||||||
Workspace = 'workspace',
|
Workspace = 'workspace',
|
||||||
|
Page = 'page',
|
||||||
Space = 'space',
|
Space = 'space',
|
||||||
Settings = 'settings',
|
Settings = 'settings',
|
||||||
Unknown = 'unknown',
|
Unknown = 'unknown',
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { isEqual } from 'lodash-es';
|
|
||||||
import type { Socket } from 'socket.io-client';
|
import type { Socket } from 'socket.io-client';
|
||||||
import { Manager } from 'socket.io-client';
|
import { Manager } from 'socket.io-client';
|
||||||
import {
|
import {
|
||||||
@@ -191,23 +190,6 @@ function setupAffineAwareness(
|
|||||||
rootDoc: Doc,
|
rootDoc: Doc,
|
||||||
awareness: Awareness
|
awareness: Awareness
|
||||||
) {
|
) {
|
||||||
let lastAwarenessState: Map<number, any> = new Map();
|
|
||||||
// can't compare on update binary because the protocol will encode clock in it but the state is still the same
|
|
||||||
const compareAwarenessState = (clients: number[]) => {
|
|
||||||
const newAwarenessState = new Map();
|
|
||||||
clients.forEach(client => {
|
|
||||||
newAwarenessState.set(client, awareness.states.get(client));
|
|
||||||
});
|
|
||||||
|
|
||||||
const equal = isEqual(lastAwarenessState, newAwarenessState);
|
|
||||||
|
|
||||||
if (!equal) {
|
|
||||||
lastAwarenessState = newAwarenessState;
|
|
||||||
}
|
|
||||||
|
|
||||||
return equal;
|
|
||||||
};
|
|
||||||
|
|
||||||
const awarenessBroadcast = ({
|
const awarenessBroadcast = ({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
awarenessUpdate,
|
awarenessUpdate,
|
||||||
@@ -235,11 +217,6 @@ function setupAffineAwareness(
|
|||||||
...cur,
|
...cur,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// hit the last awareness update cache, skip
|
|
||||||
if (compareAwarenessState(changedClients)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = encodeAwarenessUpdate(awareness, changedClients);
|
const update = encodeAwarenessUpdate(awareness, changedClients);
|
||||||
uint8ArrayToBase64(update)
|
uint8ArrayToBase64(update)
|
||||||
.then(encodedUpdate => {
|
.then(encodedUpdate => {
|
||||||
|
|||||||
Reference in New Issue
Block a user