From 6de0273d4548c7bed44a6462006e6a806d03e1d2 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Thu, 8 Jan 2026 11:48:29 +0100 Subject: [PATCH] Process notifications by grouping them per project with caching (#30439) * Add caching for project updates and file diffs in notifications processing * Simplify filterNotificationsByPreferences function * NotificationsEmailBuilder class * fix cachedRecipient issue * change processing to group per project * remove updates cache * clear cache after processing a project * refactor: update sendNotificationsForProject to accept project as parameter * fix unit tests * apply review suggestions * feat: add migration script for updating emailNotifications indexes * refactor: update sendNotificationsForProject to accept projectId * refactor: simplify fileTreeDiff result assigning * fix tests GitOrigin-RevId: bfed061864ba7314f85cf97b7adaeef62c8c5f00 --- ...142959_emailNotifications_index_update.mjs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tools/migrations/20251222142959_emailNotifications_index_update.mjs diff --git a/tools/migrations/20251222142959_emailNotifications_index_update.mjs b/tools/migrations/20251222142959_emailNotifications_index_update.mjs new file mode 100644 index 0000000000..ad4cb8dfbd --- /dev/null +++ b/tools/migrations/20251222142959_emailNotifications_index_update.mjs @@ -0,0 +1,52 @@ +/* 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: { + user_id: 1, + recipient_id: 1, + project_id: 1, + }, + name: 'user_id_1_recipient_id_1_project_id_1', + }, + { + key: { + recipient_id: 1, + }, + name: 'recipientId_1', + expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours + }, +] + +const newIndexes = [ + { + key: { + project_id: 1, + }, + name: 'project_id_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, +}