fix: Document subscriptions backfill not recursive
This commit is contained in:
@@ -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,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user