+ self.findAll(query).asCallback(function (err, requests) {
+ if (err) return callback(err)
+
+ const requestsGrouped = groupAndTruncateRequests(requests, limitRequestsPerPod)
+ return callback(err, requestsGrouped)
+ })
+ })
+}
+
+function groupAndTruncateRequests (requests, limitRequestsPerPod) {
+ const requestsGrouped = {}
+
+ requests.forEach(function (request) {
+ request.Pods.forEach(function (pod) {
+ if (!requestsGrouped[pod.id]) requestsGrouped[pod.id] = []
+
+ if (requestsGrouped[pod.id].length < limitRequestsPerPod) {
+ requestsGrouped[pod.id].push({
+ request,
+ pod
+ })
+ }
+ })