* tidy * Add title to HTML export * fix: Add compatability for documents without collab state * Add HTML download option to UI * docs * fix nodes that required document to render * Refactor to allow for styling of HTML export * div>article for easier programatic content extraction * Allow DocumentHelper to be used with Revisions * Add revisions.diff endpoint, first version * Allow arbitrary revisions to be compared * test * HTML driven revision viewer * fix: Dark mode styles for document diffs * Add revision restore button to header * test * Support RTL languages in revision history viewer * fix: RTL support Remove unneccessary API requests * Prefetch revision data * Animate history sidebar * fix: Cannot toggle history from timestamp fix: Animation on each revision click * Clarify currently editing history item
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import env from "@server/env";
|
||
import Document from "@server/models/Document";
|
||
import { Event } from "@server/types";
|
||
import { globalEventQueue } from "..";
|
||
import BaseProcessor from "./BaseProcessor";
|
||
|
||
export default class DebounceProcessor extends BaseProcessor {
|
||
static applicableEvents: Event["name"][] = [
|
||
"documents.update",
|
||
"documents.update.delayed",
|
||
];
|
||
|
||
async perform(event: Event) {
|
||
switch (event.name) {
|
||
case "documents.update": {
|
||
globalEventQueue.add(
|
||
{ ...event, name: "documents.update.delayed" },
|
||
{
|
||
// speed up revision creation in development, we don't have all the
|
||
// time in the world.
|
||
delay: (env.ENVIRONMENT === "development" ? 1 : 5) * 60 * 1000,
|
||
}
|
||
);
|
||
break;
|
||
}
|
||
|
||
case "documents.update.delayed": {
|
||
const document = await Document.findByPk(event.documentId, {
|
||
attributes: ["updatedAt"],
|
||
});
|
||
|
||
// If the document has been deleted then prevent further processing
|
||
if (!document) {
|
||
return;
|
||
}
|
||
|
||
// If the document has been updated since we initially queued the delayed
|
||
// event then abort, there must be another updated event in the queue –
|
||
// this functions as a simple distributed debounce.
|
||
if (document.updatedAt > new Date(event.createdAt)) {
|
||
return;
|
||
}
|
||
|
||
globalEventQueue.add({ ...event, name: "documents.update.debounced" });
|
||
break;
|
||
}
|
||
|
||
default:
|
||
}
|
||
}
|
||
}
|