remove unused indexes
This commit is contained in:
1 parent
658c7c090f
commit
3f8198f3df
2 files changed
+44
-11
No files matched your search
@@ -315,12 +315,5 @@ CheckSchema.index({
|
|||||||
"metadata.monitorId": 1,
|
"metadata.monitorId": 1,
|
||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
});
|
});
|
||||||
CheckSchema.index({ "metadata.teamId": 1, status: 1, createdAt: -1 });
|
|
||||||
CheckSchema.index({
|
|
||||||
"metadata.teamId": 1,
|
|
||||||
"metadata.monitorId": 1,
|
|
||||||
status: 1,
|
|
||||||
createdAt: -1,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const Check = mongoose.model<ICheck>("Check", CheckSchema);
|
export const Check = mongoose.model<ICheck>("Check", CheckSchema);
|
||||||
@@ -251,16 +251,56 @@ class CheckService implements ICheckService {
|
|||||||
createdAt: { $gte: startDate, $lte: new Date() },
|
createdAt: { $gte: startDate, $lte: new Date() },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Has-more pagination: over-fetch by 1 to infer existence of a next page
|
|
||||||
const pageSizePlusOne = rowsPerPage + 1;
|
const pageSizePlusOne = rowsPerPage + 1;
|
||||||
const docs = await Check.find(match)
|
const docs = await Check.find(match)
|
||||||
.populate({ path: "metadata.monitorId", select: "name" })
|
|
||||||
.sort({ createdAt: -1 })
|
.sort({ createdAt: -1 })
|
||||||
.skip(page * rowsPerPage)
|
.skip(page * rowsPerPage)
|
||||||
.limit(pageSizePlusOne);
|
.limit(pageSizePlusOne)
|
||||||
|
.select({
|
||||||
|
_id: 1,
|
||||||
|
status: 1,
|
||||||
|
httpStatusCode: 1,
|
||||||
|
message: 1,
|
||||||
|
responseTime: 1,
|
||||||
|
createdAt: 1,
|
||||||
|
"metadata.monitorId": 1,
|
||||||
|
"metadata.teamId": 1,
|
||||||
|
"metadata.type": 1,
|
||||||
|
});
|
||||||
|
|
||||||
const hasMore = docs.length > rowsPerPage;
|
const hasMore = docs.length > rowsPerPage;
|
||||||
const checks = hasMore ? docs.slice(0, rowsPerPage) : docs;
|
const limited = hasMore ? docs.slice(0, rowsPerPage) : docs;
|
||||||
|
|
||||||
|
const monitorIds = Array.from(
|
||||||
|
new Set(
|
||||||
|
limited
|
||||||
|
.map((d) => d?.metadata?.monitorId)
|
||||||
|
.filter((v): v is mongoose.Types.ObjectId => !!v)
|
||||||
|
.map((v) => v.toString())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
let nameById = new Map<string, string>();
|
||||||
|
if (monitorIds.length > 0) {
|
||||||
|
const monitors = await Monitor.find({ _id: { $in: monitorIds } }).select({
|
||||||
|
_id: 1,
|
||||||
|
name: 1,
|
||||||
|
});
|
||||||
|
nameById = new Map(monitors.map((m) => [m._id.toString(), m.name]));
|
||||||
|
}
|
||||||
|
|
||||||
|
const checks = limited.map((doc) => {
|
||||||
|
const asObj = doc.toObject();
|
||||||
|
const idStr = asObj?.metadata?.monitorId?.toString?.() ?? "";
|
||||||
|
const name = idStr ? nameById.get(idStr) : undefined;
|
||||||
|
if (name) {
|
||||||
|
asObj.metadata = asObj.metadata || {};
|
||||||
|
(asObj.metadata as any).monitorId = { name } as any;
|
||||||
|
}
|
||||||
|
return asObj as ICheck;
|
||||||
|
});
|
||||||
|
|
||||||
return { checks, hasMore };
|
return { checks, hasMore };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user