fix: Document subscriptions backfill not recursive

This commit is contained in:
Tom Moor
2022-08-27 11:58:21 +02:00
parent 1c8fadbe02
commit 922bf53753
2 changed files with 12 additions and 13 deletions

View File

@@ -14,7 +14,6 @@ import {
NotificationSetting, NotificationSetting,
Subscription, Subscription,
} from "@server/models"; } from "@server/models";
import { can } from "@server/policies";
import { import {
CollectionEvent, CollectionEvent,
RevisionEvent, RevisionEvent,
@@ -133,16 +132,14 @@ export default class NotificationsProcessor extends BaseProcessor {
const users = await document.collaborators({ transaction }); const users = await document.collaborators({ transaction });
for (const user of users) { for (const user of users) {
if (user && can(user, "subscribe", document)) { await subscriptionCreator({
await subscriptionCreator({ user,
user, documentId: document.id,
documentId: document.id, event: "documents.update",
event: "documents.update", resubscribe: false,
resubscribe: false, transaction,
transaction, ip: event.ip,
ip: event.ip, });
});
}
} }
}); });
}; };

View File

@@ -1,12 +1,12 @@
import "./bootstrap"; import "./bootstrap";
import { Subscription, Document } from "@server/models"; import { Subscription, Document } from "@server/models";
const limit = 100; const limit = 1000;
let page = parseInt(process.argv[2], 10); let page = parseInt(process.argv[2], 10);
page = Number.isNaN(page) ? 0 : page; page = Number.isNaN(page) ? 0 : page;
export default async function main(exit = false) { export default async function main(exit = false) {
const work = async (page: number) => { const work = async (page: number): Promise<void> => {
console.log(`Backfill subscription… page ${page}`); console.log(`Backfill subscription… page ${page}`);
// Retrieve all documents within set limit. // Retrieve all documents within set limit.
@@ -36,6 +36,8 @@ export default async function main(exit = false) {
continue; continue;
} }
} }
return documents.length === limit ? work(page + 1) : undefined;
}; };
await work(page); await work(page);