add indexes
This commit is contained in:
1 parent
52e598a66e
commit
8a986d2e58
6 files changed
+28
-11
No files matched your search
@@ -178,10 +178,15 @@ class MongoChecksRepistory implements IChecksRepository {
|
||||
}
|
||||
const mongoIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
||||
const limitPerMonitor = 25;
|
||||
const maxIntervalMs = Number(10 * 60 * 1000);
|
||||
const bufferMs = Number(maxIntervalMs);
|
||||
const lookbackMs = 25 * maxIntervalMs + bufferMs;
|
||||
const cutoffDate = new Date(Date.now() - lookbackMs);
|
||||
const checkGroups = await CheckModel.aggregate([
|
||||
{
|
||||
$match: {
|
||||
"metadata.monitorId": { $in: mongoIds },
|
||||
createdAt: { $gte: cutoffDate },
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -197,6 +202,7 @@ class MongoChecksRepistory implements IChecksRepository {
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
return checkGroups.reduce<LatestChecksMap>((acc, group) => {
|
||||
const monitorId = group._id.toString();
|
||||
acc[monitorId] = (group.latestChecks ?? []).map((doc: CheckDocument) => this.toEntity(doc));
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface TeamQueryConfig {
|
||||
export interface IMonitorsRepository {
|
||||
// create
|
||||
create(monitor: Monitor, teamId: string, userId: string): Promise<Monitor | null>;
|
||||
createBulkMonitors(monitors: Monitor[]): Promise<Monitor[]>;
|
||||
// single fetch
|
||||
findById(monitorId: string): Promise<Monitor | null>;
|
||||
|
||||
|
||||
@@ -12,6 +12,12 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
return this.toEntity(saved);
|
||||
};
|
||||
|
||||
createBulkMonitors = async (monitors: Monitor[]): Promise<Monitor[]> => {
|
||||
const newMonitors = monitors.map((monitor) => new MonitorModel({ ...monitor, notifications: undefined }));
|
||||
await MonitorModel.bulkSave(newMonitors);
|
||||
return monitors;
|
||||
};
|
||||
|
||||
findById = async (MonitorModelId: string): Promise<Monitor> => {
|
||||
const monitor = await MonitorModel.findById(MonitorModelId);
|
||||
if (!monitor) {
|
||||
|
||||
Reference in new issue
Block a user