From 9db3c931161adfbeb6fc52d3e4cf621fb9a4955f Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sun, 7 Mar 2021 15:58:15 +0200 Subject: [PATCH] Speed improvement: Delete presences older than one week, and add index to presences serverId. Thanks to xet7 ! Related #3345 --- models/presences.js | 12 ++++++++++++ server/notifications/outgoing.js | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 models/presences.js diff --git a/models/presences.js b/models/presences.js new file mode 100644 index 000000000..94c8fdabb --- /dev/null +++ b/models/presences.js @@ -0,0 +1,12 @@ +if (Meteor.isServer) { + Meteor.startup(() => { + // Date of 7 days ago + let lastWeek = new Date(); + lastWeek.setDate(lastWeek.getDate() - 7); + + presences.remove({ ttl: { $lte: lastWeek } }); + + // Create index for serverId that is queried often + presences._collection._ensureIndex({ serverId: -1 }); + }); +} diff --git a/server/notifications/outgoing.js b/server/notifications/outgoing.js index 5855e005e..1de7824e6 100644 --- a/server/notifications/outgoing.js +++ b/server/notifications/outgoing.js @@ -63,7 +63,7 @@ if (Meteor.isServer) { 'swimlaneId', 'customField', 'customFieldValue', - 'attachmentId' + 'attachmentId', ]; const responseFunc = data => { const paramCommentId = data.commentId; @@ -125,7 +125,7 @@ if (Meteor.isServer) { 'oldSwimlane', 'label', 'attachment', - 'attachmentId' + 'attachmentId', ].forEach(key => { if (quoteParams[key]) quoteParams[key] = `"${params[key]}"`; });