-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Problem
The activities lookup in the listAirQoActive
method in src/device-registry/models/Site.js
(around lines 976-982) is currently unbounded and can cause memory issues and exploded response sizes.
Current Implementation
.lookup({
from: "activities",
localField: "_id",
foreignField: "site_id",
as: "activities",
})
Proposed Solution
Mirror the guarded lookup pattern used in the list()
method by:
- Adding
maxActivities
parsing and capping at the start oflistAirQoActive
- Replacing the simple lookup with a pipeline-based lookup that includes:
$match
on site_id$sort
by createdAt descending$limit
using maxActivities$project
to only include needed fields
Benefits
- Prevents memory exhaustion from large activity datasets
- Maintains consistent behavior with the
list()
method - Allows configurable activity limits while providing sensible defaults
References
- Original PR: enhance the response details of devices and sites #5170
- Code Review Comment: enhance the response details of devices and sites #5170 (comment)
Requested by
Metadata
Metadata
Assignees
Labels
No labels