From bfa70bf43ba39a611e48cd56a1ecf93aec10f2c8 Mon Sep 17 00:00:00 2001 From: Jimmy Domagala-Tang Date: Thu, 23 Oct 2025 10:04:02 -0400 Subject: [PATCH] feat: handle determining delay and when to send at notification processing instead of managing scheduledAt. this removes the need for scheduledAt as we will do the scheduling calculations at processing time GitOrigin-RevId: d0bbd5adc29ab58a797c171b55aabfda1cec39ea --- services/web/config/settings.defaults.js | 8 +++- ...ns_index_from_scheduledAt_to_createdAt.mjs | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tools/migrations/20251023094210_change_emailtNotifications_index_from_scheduledAt_to_createdAt.mjs diff --git a/services/web/config/settings.defaults.js b/services/web/config/settings.defaults.js index 93290465f5..91efc0c6f6 100644 --- a/services/web/config/settings.defaults.js +++ b/services/web/config/settings.defaults.js @@ -715,10 +715,14 @@ module.exports = { parseInt(process.env.OVERLEAF_PROJECT_HARD_DELETION_DELAY, 10) || 1000 * 60 * 60 * 24 * 90, // 90 days - // Delay before sending comment mention notifications - commentMentionDelay: + // Maximum Delay before sending comment mention notifications + commentMentionMaxDelay: parseInt(process.env.COMMENT_MENTION_DELAY_MINUTES) || 30 * 60 * 1000, // 30 minutes + // Comment mention notifications will wait at least this long before being sent + commentMentionMinDelay: + parseInt(process.env.COMMENT_MENTION_DELAY_MINUTES) || 10 * 60 * 1000, // 10 minutes + // Maximum JSON size in HTTP requests // We should be able to process twice the max doc length, to allow for // - the doc content diff --git a/tools/migrations/20251023094210_change_emailtNotifications_index_from_scheduledAt_to_createdAt.mjs b/tools/migrations/20251023094210_change_emailtNotifications_index_from_scheduledAt_to_createdAt.mjs new file mode 100644 index 0000000000..9a27e3e024 --- /dev/null +++ b/tools/migrations/20251023094210_change_emailtNotifications_index_from_scheduledAt_to_createdAt.mjs @@ -0,0 +1,44 @@ +/* eslint-disable no-unused-vars */ + +import Helpers from './lib/helpers.mjs' +import { getCollectionInternal } from './lib/mongodb.mjs' + +const tags = ['server-pro', 'saas'] + +const oldIndexes = [ + { + key: { + scheduledAt: 1, + }, + name: 'scheduledAt_1', + expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours + }, +] + +const newIndexes = [ + { + key: { + createdAt: 1, + }, + name: 'createdAt_1', + expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours + }, +] + +const migrate = async client => { + const emailNotifications = await getCollectionInternal('emailNotifications') + await Helpers.dropIndexesFromCollection(emailNotifications, oldIndexes) + await Helpers.addIndexesToCollection(emailNotifications, newIndexes) +} + +const rollback = async client => { + const emailNotifications = await getCollectionInternal('emailNotifications') + await Helpers.dropIndexesFromCollection(emailNotifications, newIndexes) + await Helpers.addIndexesToCollection(emailNotifications, oldIndexes) +} + +export default { + tags, + migrate, + rollback, +}