mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
fix: Reduce unneccessary client fetches
This commit is contained in:
1 parent
5687514fd5
commit
8ac3c17310
3 files changed
+12
-23
No files matched your search
@@ -135,6 +135,9 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
if (document?.updatedAt === documentDescriptor.updatedAt) {
|
||||
continue;
|
||||
}
|
||||
if (!document && !event.fetchIfMissing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// otherwise, grab the latest version of the document
|
||||
try {
|
||||
@@ -180,6 +183,9 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
if (collection?.updatedAt === collectionDescriptor.updatedAt) {
|
||||
continue;
|
||||
}
|
||||
if (!collection?.documents?.length && !event.fetchIfMissing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await collection?.fetchDocuments({
|
||||
|
||||
@@ -180,6 +180,7 @@ export type WebsocketEntityDeletedEvent = {
|
||||
};
|
||||
|
||||
export type WebsocketEntitiesEvent = {
|
||||
fetchIfMissing?: boolean;
|
||||
documentIds: { id: string; updatedAt?: string }[];
|
||||
collectionIds: { id: string; updatedAt?: string }[];
|
||||
groupIds: { id: string; updatedAt?: string }[];
|
||||
|
||||
@@ -36,6 +36,7 @@ import { Event } from "../../types";
|
||||
export default class WebsocketsProcessor {
|
||||
public async perform(event: Event, socketio: Server) {
|
||||
switch (event.name) {
|
||||
case "documents.create":
|
||||
case "documents.publish":
|
||||
case "documents.unpublish":
|
||||
case "documents.restore":
|
||||
@@ -46,10 +47,14 @@ export default class WebsocketsProcessor {
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
if (event.name === "documents.create" && document.importId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const channels = await this.getDocumentEventChannels(event, document);
|
||||
return socketio.to(channels).emit("entities", {
|
||||
event: event.name,
|
||||
fetchIfMissing: true,
|
||||
documentIds: [
|
||||
{
|
||||
id: document.id,
|
||||
@@ -86,29 +91,6 @@ export default class WebsocketsProcessor {
|
||||
return socketio.to(channels).emit(event.name, data);
|
||||
}
|
||||
|
||||
case "documents.create": {
|
||||
const document = await Document.findByPk(event.documentId);
|
||||
if (!document || document.importId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const channels = await this.getDocumentEventChannels(event, document);
|
||||
return socketio.to(channels).emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
id: document.id,
|
||||
updatedAt: document.updatedAt,
|
||||
},
|
||||
],
|
||||
collectionIds: [
|
||||
{
|
||||
id: document.collectionId,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
case "documents.move": {
|
||||
const documents = await Document.findAll({
|
||||
where: {
|
||||
|
||||
Reference in new issue
Block a user