Skip to content

Commit ee1ba32

Browse files
committed
fix(api): correct dailyEvents $limit gating
1 parent a973109 commit ee1ba32

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

src/dataLoaders.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,27 @@ export default class DataLoaders {
6868
* Batching function for resolving entities from their ids
6969
* @param collectionName - collection name to get entities
7070
* @param ids - ids for resolving
71-
* @param projection - optional mongo projection to limit returned fields
7271
*/
7372
private async batchByIds<T extends { _id: ObjectId }>(
7473
collectionName: string,
75-
ids: ReadonlyArray<string>,
76-
projection?: Record<string, 0 | 1>
74+
ids: ReadonlyArray<string>
7775
): Promise<(WithId<T> | null)[]> {
78-
return this.batchByField<T, '_id'>(
79-
collectionName,
80-
'_id',
81-
ids.map(id => new ObjectId(id)),
82-
projection
83-
);
76+
return this.batchByField<T, '_id'>(collectionName, '_id', ids.map(id => new ObjectId(id)));
8477
}
8578

8679
/**
8780
* Batching function for resolving entities by certain field
8881
* @param collectionName - collection name to get entities
8982
* @param fieldName - field name to resolve
9083
* @param values - values for resolving
91-
* @param projection - optional mongo projection to limit returned fields
9284
*/
9385
private async batchByField<
9486
T extends Record<string, any>,
9587
FieldType extends keyof T
9688
>(
9789
collectionName: string,
9890
fieldName: FieldType,
99-
values: ReadonlyArray<T[FieldType]>,
100-
projection?: Record<string, 0 | 1>
91+
values: ReadonlyArray<T[FieldType]>
10192
): Promise<(WithId<T> | null)[]> {
10293
type Doc = WithId<T>;
10394
const valuesMap = new Map<string, FieldType>();
@@ -108,10 +99,9 @@ export default class DataLoaders {
10899

109100
const queryResult = await this.dbConnection
110101
.collection<T>(collectionName)
111-
.find(
112-
{ [fieldName]: { $in: Array.from(valuesMap.values()) } } as any,
113-
projection ? { projection } : {}
114-
)
102+
.find({
103+
[fieldName]: { $in: Array.from(valuesMap.values()) },
104+
} as any)
115105
.toArray();
116106

117107
/**

src/models/eventsFactory.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,14 @@ class EventsFactory extends Factory {
403403
return { 'event.assignee': String(assignee) };
404404
})();
405405

406-
/** When false, $limit can move before the $lookups. */
406+
/**
407+
* These filters match joined event.* fields, so their $match must run
408+
* after the lookups. With none set, $limit can move before the lookups
409+
* and skip joining rows we'd drop anyway (~8.8s).
410+
* Trim search to match searchFilter's own condition.
411+
*/
407412
const hasContentFilters =
408-
escapedSearch.length > 0 ||
413+
search.trim().length > 0 ||
409414
Boolean(release) ||
410415
Boolean(assignee) ||
411416
Object.keys(matchFilter).length > 0;

0 commit comments

Comments
 (0)