move filtering to the monitors facet

This commit is contained in:
Alex Holliday committed 2025-01-08 14:17:29 -08:00
1 parent 62541f3fdd
commit 40fbe4a822
2 files changed
+14 -9

No files matched your search

+2 -2
View File
@@ -137,8 +137,8 @@ const UptimeMonitors = () => {
const triggerUpdate = () => {
setMonitorUpdateTrigger((prev) => !prev);
};
const totalMonitors = monitorsSummary.totalMonitors;
const hasMonitors = totalMonitors > 0;
const totalMonitors = monitorsSummary?.totalMonitors ?? 0;
const hasMonitors = monitorsSummary?.totalMonitors ?? 0;
const canAddMonitor = isAdmin && hasMonitors;
return (
+12 -7
View File
@@ -523,13 +523,6 @@ const getMonitorsByTeamId = async (req) => {
const sort = { [field]: order === "asc" ? 1 : -1 };
if (filter !== undefined) {
matchStage.$or = [
{ name: { $regex: filter, $options: "i" } },
{ url: { $regex: filter, $options: "i" } },
];
}
const results = await Monitor.aggregate([
{ $match: matchStage },
{
@@ -563,6 +556,18 @@ const getMonitorsByTeamId = async (req) => {
},
],
monitors: [
...(filter !== undefined
? [
{
$match: {
$or: [
{ name: { $regex: filter, $options: "i" } },
{ url: { $regex: filter, $options: "i" } },
],
},
},
]
: []),
{ $sort: sort },
{ $skip: skip },
...(rowsPerPage ? [{ $limit: rowsPerPage }] : []),