chore: Refactor backlinks and revisions (#1611)

* Update backlinks service to not rely on revisions

* fix: Add missing index for finding backlinks

* Debounce revision creation (#1616)

* refactor debounce logic to service

* Debounce slack notification

* Revisions created by service

* fix: Revision sidebar latest

* test: Add tests for notifications
This commit is contained in:
Tom Moor
2020-11-01 10:26:39 -08:00
committed by GitHub
parent 7735aa12d7
commit 3d09c8f655
20 changed files with 487 additions and 246 deletions

View File

@@ -1,11 +1,14 @@
// @flow
import * as Sentry from "@sentry/node";
import debug from "debug";
import services from "./services";
import { createQueue } from "./utils/queue";
const log = debug("services");
export type UserEvent =
| {
name: | 'users.create' // eslint-disable-line
name: | "users.create" // eslint-disable-line
| "users.update"
| "users.suspend"
| "users.activate"
@@ -26,7 +29,7 @@ export type UserEvent =
export type DocumentEvent =
| {
name: | 'documents.create' // eslint-disable-line
name: | "documents.create" // eslint-disable-line
| "documents.publish"
| "documents.delete"
| "documents.pin"
@@ -53,20 +56,43 @@ export type DocumentEvent =
},
}
| {
name: "documents.update",
name: | "documents.update" // eslint-disable-line
| "documents.update.delayed"
| "documents.update.debounced",
documentId: string,
collectionId: string,
createdAt: string,
teamId: string,
actorId: string,
data: {
title: string,
autosave: boolean,
done: boolean,
},
}
| {
name: "documents.title_change",
documentId: string,
collectionId: string,
createdAt: string,
teamId: string,
actorId: string,
data: {
title: string,
previousTitle: string,
},
};
export type RevisionEvent = {
name: "revisions.create",
documentId: string,
collectionId: string,
teamId: string,
};
export type CollectionEvent =
| {
name: | 'collections.create' // eslint-disable-line
name: | "collections.create" // eslint-disable-line
| "collections.update"
| "collections.delete",
collectionId: string,
@@ -120,7 +146,8 @@ export type Event =
| DocumentEvent
| CollectionEvent
| IntegrationEvent
| GroupEvent;
| GroupEvent
| RevisionEvent;
const globalEventsQueue = createQueue("global events");
const serviceEventsQueue = createQueue("service events");
@@ -132,7 +159,7 @@ globalEventsQueue.process(async (job) => {
const service = services[name];
if (service.on) {
serviceEventsQueue.add(
{ service: name, ...job.data },
{ ...job.data, service: name },
{ removeOnComplete: true }
);
}
@@ -145,6 +172,8 @@ serviceEventsQueue.process(async (job) => {
const service = services[event.service];
if (service.on) {
log(`${event.service} processing ${event.name}`);
service.on(event).catch((error) => {
if (process.env.SENTRY_DSN) {
Sentry.withScope(function (scope) {