From 0d12798dd2a8488df83537a312be485c62d74aa6 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 17 Sep 2024 08:12:23 +0800 Subject: [PATCH 1/3] Remove checks from monitor query --- Client/src/Pages/Incidents/index.jsx | 3 ++- Server/controllers/monitorController.js | 1 - Server/db/mongo/modules/monitorModule.js | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index 8bd2928cb..f70703828 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -28,7 +28,7 @@ const Incidents = () => { const res = await networkService.getMonitorsByTeamId( authState.authToken, authState.user.teamId, - 1, + -1, null, null, null, @@ -36,6 +36,7 @@ const Incidents = () => { null, null ); + console.log(res.data.data); // Reduce to a lookup object for 0(1) lookup if (res?.data?.data?.monitors?.length > 0) { const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => { diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 8011cec7d..f5bd98b74 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -271,7 +271,6 @@ const getMonitorsByTeamId = async (req, res, next) => { try { const teamId = req.params.teamId; const monitors = await req.db.getMonitorsByTeamId(req, res); - return res.json({ success: true, msg: successMessages.MONITOR_GET_BY_USER_ID(teamId), diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 42947f38e..58ac2e8c7 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -373,12 +373,18 @@ const getMonitorsByTeamId = async (req, res) => { sortOrder = -1; } else sortOrder = -1; - // This effectively removes limit, returning all checks - if (limit === undefined) limit = 0; - const monitors = await Monitor.find(monitorQuery) .skip(skip) .limit(rowsPerPage); + + // Early return if limit is set to -1, indicating we don't want any checks + if (limit === -1) { + return { monitors, monitorCount: monitorsCount }; + } + + // This effectively removes limit, returning all checks + if (limit === undefined) limit = 0; + // Map each monitor to include its associated checks const monitorsWithChecks = await Promise.all( monitors.map(async (monitor) => { From 3ba6f5a56b7e97de22564b49eee1ca762b47295e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 17 Sep 2024 08:46:06 +0800 Subject: [PATCH 2/3] Fix type error --- Server/db/mongo/modules/monitorModule.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 58ac2e8c7..344fce188 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -378,7 +378,8 @@ const getMonitorsByTeamId = async (req, res) => { .limit(rowsPerPage); // Early return if limit is set to -1, indicating we don't want any checks - if (limit === -1) { + if (limit === "-1") { + console.log("early return"); return { monitors, monitorCount: monitorsCount }; } From 113d577ad25e8240463a8ac2a71a7a76a3d77d05 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 17 Sep 2024 08:46:55 +0800 Subject: [PATCH 3/3] remove console log --- Server/db/mongo/modules/monitorModule.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 344fce188..a7c00d726 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -379,7 +379,6 @@ const getMonitorsByTeamId = async (req, res) => { // Early return if limit is set to -1, indicating we don't want any checks if (limit === "-1") { - console.log("early return"); return { monitors, monitorCount: monitorsCount }; }