Perf/api mongo projections#651
Open
Kuchizu wants to merge 3 commits into
Open
Conversation
e11sy
approved these changes
May 6, 2026
neSpecc
reviewed
May 12, 2026
| return { 'event.assignee': String(assignee) }; | ||
| })(); | ||
|
|
||
| /** When false, $limit can move before the $lookups. */ |
Member
There was a problem hiding this comment.
please explain in docs why it is useful
| collectionName: string, | ||
| ids: ReadonlyArray<string> | ||
| ids: ReadonlyArray<string>, | ||
| projection?: Record<string, 0 | 1> |
Member
There was a problem hiding this comment.
I see no usages. Where is it used?
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes the findDailyEventsPortion MongoDB aggregation for the no-content-filters case by moving $limit earlier (before $lookup stages) and extends internal DataLoader batching helpers to optionally accept MongoDB projections to reduce fetched fields.
Changes:
- In
findDailyEventsPortion, conditionally applies$limitbefore$lookupstages when no content filters are present, keeping$match + $limitafter lookups when filters exist. - Adds an optional
projectionparameter to DataLoader batch helpers (batchByIds/batchByField) and forwards it to MongoDB.find(...). - Bumps package version to
1.5.1.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/models/eventsFactory.js |
Moves $limit earlier in the daily-events aggregation when filters are absent to reduce lookup workload. |
src/dataLoaders.ts |
Adds optional MongoDB projection support to batch helper methods used by DataLoaders. |
package.json |
Version bump from 1.5.0 to 1.5.1. |
Comments suppressed due to low confidence (1)
src/dataLoaders.ts:107
valuesMapis typed asMap<string, FieldType>, but it stores the actual field values (T[FieldType]). Updating it toMap<string, T[FieldType]>would make the intent clearer and keep types accurate when building the$inarray and mapping results.
type Doc = WithId<T>;
const valuesMap = new Map<string, FieldType>();
for (const value of values) {
valuesMap.set(value.toString(), value);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+407
to
+408
| const hasContentFilters = | ||
| escapedSearch.length > 0 || |
Comment on lines
109
to
+114
| const queryResult = await this.dbConnection | ||
| .collection<T>(collectionName) | ||
| .find({ | ||
| [fieldName]: { $in: Array.from(valuesMap.values()) }, | ||
| } as any) | ||
| .find( | ||
| { [fieldName]: { $in: Array.from(valuesMap.values()) } } as any, | ||
| projection ? { projection } : {} | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
findDailyEventsPortion: $limit before $lookups when no content filter (was the 8.8s prod aggregation). DataLoader batch helpers gain optional projection arg.