@justair/justair-library 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/models/admin.js +9 -1
- package/src/models/alerts.js +10 -1
- package/src/models/events.js +6 -0
- package/src/models/jobs.js +9 -0
- package/src/models/measurements.js +8 -3
- package/src/models/monitors.js +21 -2
- package/src/models/organizations.js +7 -0
package/package.json
CHANGED
package/src/models/admin.js
CHANGED
|
@@ -15,7 +15,15 @@ const adminSchema = mongoose.Schema({
|
|
|
15
15
|
timestamps: true
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// Organization-based admin queries
|
|
19
|
+
adminSchema.index({ orgId: 1, isActive: 1 });
|
|
20
|
+
// Email-based login with active status (case-insensitive handled in app)
|
|
21
|
+
adminSchema.index({ email: 1, isActive: 1 });
|
|
22
|
+
// Permission-based queries
|
|
23
|
+
adminSchema.index({ orgId: 1, permissionName: 1 });
|
|
24
|
+
|
|
25
|
+
// Keep individual email index for backward compatibility
|
|
26
|
+
adminSchema.index({ email: 1 });
|
|
19
27
|
|
|
20
28
|
|
|
21
29
|
const Admin = mongoose.model('Admin', adminSchema);
|
package/src/models/alerts.js
CHANGED
|
@@ -47,10 +47,19 @@ const alertsSchema = mongoose.Schema(
|
|
|
47
47
|
}
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
+
// Organization-based queries with timestamp ordering
|
|
51
|
+
alertsSchema.index({ orgId: 1, updatedAt: -1 });
|
|
52
|
+
// Monitor-based queries for lookups with timestamp ordering
|
|
53
|
+
alertsSchema.index({ monitorId: 1, updatedAt: -1 });
|
|
54
|
+
// Status-based filtering with organization and timestamp
|
|
55
|
+
alertsSchema.index({ orgId: 1, status: 1, updatedAt: -1 });
|
|
56
|
+
// Alert configuration matching - already optimal
|
|
57
|
+
alertsSchema.index({ alertConfigurationId: 1 });
|
|
58
|
+
|
|
59
|
+
// Keep individual indexes for backward compatibility
|
|
50
60
|
alertsSchema.index({ orgId: 1 });
|
|
51
61
|
alertsSchema.index({ monitorId: 1 });
|
|
52
62
|
alertsSchema.index({ type: 1 });
|
|
53
|
-
alertsSchema.index({ alertConfigurationId: 1 });
|
|
54
63
|
|
|
55
64
|
const alertsAuditSchema = mongoose.Schema(
|
|
56
65
|
{
|
package/src/models/events.js
CHANGED
|
@@ -44,6 +44,12 @@ const eventsSchema = mongoose.Schema(
|
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
+
// Primary lookup pattern from monitors - for $lookup operations
|
|
48
|
+
eventsSchema.index({ monitorId: 1, createdAt: -1 });
|
|
49
|
+
// Date range filtering index
|
|
50
|
+
eventsSchema.index({ monitorId: 1, updatedAt: -1 });
|
|
51
|
+
|
|
52
|
+
// Keep individual indexes for other query patterns
|
|
47
53
|
eventsSchema.index({ monitorId: 1 });
|
|
48
54
|
eventsSchema.index({ parameter: 1 });
|
|
49
55
|
|
package/src/models/jobs.js
CHANGED
|
@@ -32,6 +32,15 @@ const jobsSchema = mongoose.Schema(
|
|
|
32
32
|
|
|
33
33
|
const Jobs = mongoose.model("Jobs", jobsSchema);
|
|
34
34
|
|
|
35
|
+
// Requestor-based queries with category filtering
|
|
36
|
+
jobsSchema.index({ requestorId: 1, category: 1 });
|
|
37
|
+
// Exclude specific categories efficiently with timestamp ordering
|
|
38
|
+
jobsSchema.index({ requestorId: 1, category: 1, createdAt: -1 });
|
|
39
|
+
// Monitor-based job lookups (if monitorId field exists in resourceMetaData)
|
|
40
|
+
// Note: This may need to be adjusted based on actual schema structure
|
|
41
|
+
// jobsSchema.index({ "resourceMetaData.monitorId": 1, updatedAt: -1 });
|
|
42
|
+
|
|
43
|
+
// Keep individual indexes for backward compatibility
|
|
35
44
|
jobsSchema.index({ requestorId: 1 });
|
|
36
45
|
jobsSchema.index({ createdAt: 1 });
|
|
37
46
|
jobsSchema.index({ category: 1 });
|
|
@@ -96,11 +96,16 @@ const measurementsSchema = mongoose.Schema(
|
|
|
96
96
|
}
|
|
97
97
|
);
|
|
98
98
|
|
|
99
|
-
// CRITICAL: Add compound
|
|
100
|
-
//
|
|
99
|
+
// CRITICAL: Add compound indexes for monitorId + timeUpdated
|
|
100
|
+
// Primary query pattern index (descending timeUpdated for latest data first)
|
|
101
101
|
measurementsSchema.index({ monitorId: 1, timeUpdated: -1 });
|
|
102
|
+
// Date range query index (ascending timeUpdated for range queries)
|
|
103
|
+
measurementsSchema.index({ monitorId: 1, timeUpdated: 1 });
|
|
102
104
|
|
|
103
|
-
//
|
|
105
|
+
// Flag-based query index for filtering by monitor and flags
|
|
106
|
+
measurementsSchema.index({ monitorId: 1, flags: 1 });
|
|
107
|
+
|
|
108
|
+
// Keep the individual indexes as they may still be useful for other queries
|
|
104
109
|
measurementsSchema.index({ monitorId: 1 });
|
|
105
110
|
measurementsSchema.index({ timeUpdated: 1 });
|
|
106
111
|
|
package/src/models/monitors.js
CHANGED
|
@@ -131,9 +131,9 @@ const monitorsSchema = mongoose.Schema(
|
|
|
131
131
|
"blue sky",
|
|
132
132
|
"aq mesh",
|
|
133
133
|
"quant aq",
|
|
134
|
-
"
|
|
134
|
+
"airGradient",
|
|
135
135
|
"oizom",
|
|
136
|
-
"metOne"
|
|
136
|
+
"metOne",
|
|
137
137
|
],
|
|
138
138
|
},
|
|
139
139
|
monitorType: String,
|
|
@@ -207,7 +207,26 @@ const monitorsSchema = mongoose.Schema(
|
|
|
207
207
|
}
|
|
208
208
|
);
|
|
209
209
|
|
|
210
|
+
// Geographic queries - already exists
|
|
210
211
|
monitorsSchema.index({ gpsLocation: "2dsphere" });
|
|
212
|
+
|
|
213
|
+
// Sponsor-based queries
|
|
214
|
+
monitorsSchema.index({ sponsor: 1, isPrivate: 1, isActive: 1 });
|
|
215
|
+
|
|
216
|
+
// Location-based filtering
|
|
217
|
+
monitorsSchema.index({ "location.city": 1, "location.state": 1 });
|
|
218
|
+
monitorsSchema.index({ "location.neighborhood": 1 });
|
|
219
|
+
monitorsSchema.index({ "location.county": 1 });
|
|
220
|
+
|
|
221
|
+
// Query parameter filtering
|
|
222
|
+
monitorsSchema.index({ monitorSupplier: 1, monitorState: 1 });
|
|
223
|
+
monitorsSchema.index({ context: 1 });
|
|
224
|
+
monitorsSchema.index({ parameters: 1 });
|
|
225
|
+
|
|
226
|
+
// Monitor lookups by supplier
|
|
227
|
+
monitorsSchema.index({ sponsor: 1, monitorSupplier: 1 });
|
|
228
|
+
|
|
229
|
+
// Keep existing single-field indexes for backward compatibility
|
|
211
230
|
monitorsSchema.index({ monitorSupplier: 1 });
|
|
212
231
|
monitorsSchema.index({ monitorIdFromSupplier: 1 });
|
|
213
232
|
monitorsSchema.index({ monitorState: 1 });
|
|
@@ -72,6 +72,13 @@ const organizationsSchema = mongoose.Schema(
|
|
|
72
72
|
}
|
|
73
73
|
);
|
|
74
74
|
|
|
75
|
+
// Name-based sorting index
|
|
76
|
+
organizationsSchema.index({ name: 1 });
|
|
77
|
+
// Connected monitors array queries
|
|
78
|
+
organizationsSchema.index({ connectedMonitors: 1 });
|
|
79
|
+
// Alert configuration queries
|
|
80
|
+
organizationsSchema.index({ _id: 1, "alertConfigurations.isActive": 1 });
|
|
81
|
+
|
|
75
82
|
const Organizations = mongoose.model("Organizations", organizationsSchema);
|
|
76
83
|
|
|
77
84
|
export { organizationsSchema, Organizations };
|