indexes
This commit is contained in:
1 parent
1ee8a873f6
commit
aa346abf5b
4 files changed
+32
-8
No files matched your search
@@ -163,5 +163,8 @@ MonitorSchema.index({ type: 1 });
|
|||||||
MonitorSchema.index({ lastCheckedAt: 1 });
|
MonitorSchema.index({ lastCheckedAt: 1 });
|
||||||
MonitorSchema.index({ createdBy: 1 });
|
MonitorSchema.index({ createdBy: 1 });
|
||||||
MonitorSchema.index({ updatedBy: 1 });
|
MonitorSchema.index({ updatedBy: 1 });
|
||||||
|
// Common filter keys used across services and routes
|
||||||
|
MonitorSchema.index({ teamId: 1 });
|
||||||
|
MonitorSchema.index({ orgId: 1 });
|
||||||
|
|
||||||
export const Monitor = mongoose.model<IMonitor>("Monitor", MonitorSchema);
|
export const Monitor = mongoose.model<IMonitor>("Monitor", MonitorSchema);
|
||||||
@@ -26,7 +26,7 @@ const MonitorStatsSchema = new Schema<IMonitorStats>(
|
|||||||
type: mongoose.Schema.Types.ObjectId,
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
ref: "Monitor",
|
ref: "Monitor",
|
||||||
immutable: true,
|
immutable: true,
|
||||||
index: true,
|
unique: true,
|
||||||
},
|
},
|
||||||
avgResponseTime: {
|
avgResponseTime: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
|||||||
@@ -92,8 +92,18 @@ const InfraNetEntrySchema = new Schema<IInfraNetEntry>(
|
|||||||
|
|
||||||
const StatsDailySchema = new Schema<IStatsDaily>(
|
const StatsDailySchema = new Schema<IStatsDaily>(
|
||||||
{
|
{
|
||||||
monitorId: { type: Schema.Types.ObjectId, ref: "Monitor", index: true, required: true },
|
monitorId: {
|
||||||
teamId: { type: Schema.Types.ObjectId, ref: "Team", index: true, required: true },
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: "Monitor",
|
||||||
|
index: true,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
teamId: {
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: "Team",
|
||||||
|
index: true,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
type: { type: String, required: true },
|
type: { type: String, required: true },
|
||||||
windowStart: { type: Date, required: true, index: true },
|
windowStart: { type: Date, required: true, index: true },
|
||||||
windowEnd: { type: Date, required: true },
|
windowEnd: { type: Date, required: true },
|
||||||
@@ -126,7 +136,6 @@ const StatsDailySchema = new Schema<IStatsDaily>(
|
|||||||
{ timestamps: true, collection: "stats_daily" }
|
{ timestamps: true, collection: "stats_daily" }
|
||||||
);
|
);
|
||||||
|
|
||||||
// One document per (monitorId, windowStart)
|
|
||||||
StatsDailySchema.index({ monitorId: 1, windowStart: 1 }, { unique: true });
|
StatsDailySchema.index({ monitorId: 1, windowStart: 1 }, { unique: true });
|
||||||
|
|
||||||
export const StatsDaily = mongoose.model<IStatsDaily>(
|
export const StatsDaily = mongoose.model<IStatsDaily>(
|
||||||
|
|||||||
@@ -87,7 +87,10 @@ export interface IInfraNetEntry {
|
|||||||
fifo_out?: number;
|
fifo_out?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IStatsHourly extends mongoose.Document, IStatsBase, IPageSpeedMetrics {
|
export interface IStatsHourly
|
||||||
|
extends mongoose.Document,
|
||||||
|
IStatsBase,
|
||||||
|
IPageSpeedMetrics {
|
||||||
cpu?: IInfraCpu;
|
cpu?: IInfraCpu;
|
||||||
memory?: IInfraMemory;
|
memory?: IInfraMemory;
|
||||||
disk?: IInfraDiskEntry[];
|
disk?: IInfraDiskEntry[];
|
||||||
@@ -166,8 +169,18 @@ const InfraNetEntrySchema = new Schema<IInfraNetEntry>(
|
|||||||
|
|
||||||
const StatsHourlySchema = new Schema<IStatsHourly>(
|
const StatsHourlySchema = new Schema<IStatsHourly>(
|
||||||
{
|
{
|
||||||
monitorId: { type: Schema.Types.ObjectId, ref: "Monitor", index: true, required: true },
|
monitorId: {
|
||||||
teamId: { type: Schema.Types.ObjectId, ref: "Team", index: true, required: true },
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: "Monitor",
|
||||||
|
index: true,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
teamId: {
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: "Team",
|
||||||
|
index: true,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
type: { type: String, required: true },
|
type: { type: String, required: true },
|
||||||
windowStart: { type: Date, required: true, index: true },
|
windowStart: { type: Date, required: true, index: true },
|
||||||
windowEnd: { type: Date, required: true },
|
windowEnd: { type: Date, required: true },
|
||||||
@@ -200,7 +213,6 @@ const StatsHourlySchema = new Schema<IStatsHourly>(
|
|||||||
{ timestamps: true, collection: "stats_hourly" }
|
{ timestamps: true, collection: "stats_hourly" }
|
||||||
);
|
);
|
||||||
|
|
||||||
// One document per (monitorId, windowStart)
|
|
||||||
StatsHourlySchema.index({ monitorId: 1, windowStart: 1 }, { unique: true });
|
StatsHourlySchema.index({ monitorId: 1, windowStart: 1 }, { unique: true });
|
||||||
|
|
||||||
export const StatsHourly = mongoose.model<IStatsHourly>(
|
export const StatsHourly = mongoose.model<IStatsHourly>(
|
||||||
|
|||||||
Reference in new issue
Block a user