mirror of
https://github.com/outline/outline.git
synced 2026-12-05 18:55:10 +03:00
* feat: Flatten collaborative state of large documents Replace edit history in large collaborative state with fresh state once a document is idle with no open sessions, and when state is over the maximum length on save. Each replacement increments a state generation that is part of the collaboration room name, so old state never merges into the new state. * fix: Refuse to load state of another generation and lock editor during reset * Remove excessive tests * fix: Reset rooms on all instances and check state generation during authentication * refactor: Schedule state flattening only for changed rooms, from PersistenceExtension * fix: Refuse API text updates applied to state of an earlier generation
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { toError } from "@shared/utils/error";
|
|
import Logger from "@server/logging/Logger";
|
|
import RedisAdapter from "@server/storage/redis";
|
|
|
|
/**
|
|
* The Redis key of the sorted set that records the instances with a
|
|
* collaboration session open for a document. Each member is an instance ID,
|
|
* scored by the time the record expires.
|
|
*
|
|
* @param documentId the ID of the document.
|
|
* @returns the Redis key.
|
|
*/
|
|
export function collaborationSessionKey(documentId: string): string {
|
|
return `collaboration:session:${documentId}`;
|
|
}
|
|
|
|
/**
|
|
* Whether a collaboration session is open for the document on any instance.
|
|
* If Redis can not be read, a session is assumed to be open.
|
|
*
|
|
* @param documentId the ID of the document.
|
|
* @returns a promise resolving to true if a session is open.
|
|
*/
|
|
export async function collaborationSessionExists(
|
|
documentId: string
|
|
): Promise<boolean> {
|
|
try {
|
|
const count = await RedisAdapter.collaborationClient.zcount(
|
|
collaborationSessionKey(documentId),
|
|
Date.now(),
|
|
"+inf"
|
|
);
|
|
return count > 0;
|
|
} catch (err) {
|
|
Logger.warn("Unable to read collaboration sessions", {
|
|
documentId,
|
|
message: toError(err).message,
|
|
});
|
|
return true;
|
|
}
|
|
}
|