-
Notifications
You must be signed in to change notification settings - Fork 2
Perf/api mongo projections #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kuchizu
wants to merge
6
commits into
master
Choose a base branch
from
perf/api-mongo-projections
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e453f3b
perf(api): apply $limit before $lookup in dailyEvents pipeline when n…
Kuchizu 8fd1cab
perf(api): support optional projection in DataLoader batch fns
Kuchizu 16b0e23
Bump version up to 1.5.1
github-actions[bot] e9a9e9b
Merge branch 'master' into perf/api-mongo-projections
Kuchizu a973109
Bump version up to 1.5.2
github-actions[bot] ee1ba32
fix(api): correct dailyEvents $limit gating
Kuchizu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,27 +68,36 @@ | |
| * Batching function for resolving entities from their ids | ||
| * @param collectionName - collection name to get entities | ||
| * @param ids - ids for resolving | ||
| * @param projection - optional mongo projection to limit returned fields | ||
| */ | ||
| private async batchByIds<T extends { _id: ObjectId }>( | ||
| collectionName: string, | ||
| ids: ReadonlyArray<string> | ||
| ids: ReadonlyArray<string>, | ||
| projection?: Record<string, 0 | 1> | ||
| ): Promise<(WithId<T> | null)[]> { | ||
| return this.batchByField<T, '_id'>(collectionName, '_id', ids.map(id => new ObjectId(id))); | ||
| return this.batchByField<T, '_id'>( | ||
| collectionName, | ||
| '_id', | ||
| ids.map(id => new ObjectId(id)), | ||
| projection | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Batching function for resolving entities by certain field | ||
| * @param collectionName - collection name to get entities | ||
| * @param fieldName - field name to resolve | ||
| * @param values - values for resolving | ||
| * @param projection - optional mongo projection to limit returned fields | ||
| */ | ||
| private async batchByField< | ||
| T extends Record<string, any>, | ||
| FieldType extends keyof T | ||
| >( | ||
| collectionName: string, | ||
| fieldName: FieldType, | ||
| values: ReadonlyArray<T[FieldType]> | ||
| values: ReadonlyArray<T[FieldType]>, | ||
| projection?: Record<string, 0 | 1> | ||
| ): Promise<(WithId<T> | null)[]> { | ||
| type Doc = WithId<T>; | ||
| const valuesMap = new Map<string, FieldType>(); | ||
|
|
@@ -99,9 +108,10 @@ | |
|
|
||
| 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 } : {} | ||
| ) | ||
|
|
||
| .toArray(); | ||
|
|
||
| /** | ||
|
|
@@ -120,7 +130,7 @@ | |
| } | ||
| } | ||
|
|
||
| /** | ||
|
Check warning on line 133 in src/dataLoaders.ts
|
||
| * Create DataLoader for events in dynamic collections `events:<projectId>` stored in the events DB | ||
| * | ||
| * @param eventsDb - MongoDB connection to the events database | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,6 +403,17 @@ class EventsFactory extends Factory { | |
| return { 'event.assignee': String(assignee) }; | ||
| })(); | ||
|
|
||
| /** When false, $limit can move before the $lookups. */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please explain in docs why it is useful |
||
| const hasContentFilters = | ||
| escapedSearch.length > 0 || | ||
|
|
||
| Boolean(release) || | ||
| Boolean(assignee) || | ||
| Object.keys(matchFilter).length > 0; | ||
|
|
||
| if (!hasContentFilters) { | ||
| pipeline.push({ $limit: limit + 1 }); | ||
| } | ||
|
|
||
| pipeline.push( | ||
| /** | ||
| * Left outer join original event on groupHash field | ||
|
|
@@ -434,21 +445,25 @@ class EventsFactory extends Factory { | |
| path: '$repetition', | ||
| preserveNullAndEmptyArrays: true, | ||
| }, | ||
| }, | ||
| { | ||
| $match: { | ||
| ...matchFilter, | ||
| ...searchFilter, | ||
| ...releaseFilter, | ||
| ...assigneeFilter, | ||
| }, | ||
| }, | ||
| { $limit: limit + 1 }, | ||
| { | ||
| $unset: 'groupHash', | ||
| } | ||
| ); | ||
|
|
||
| if (hasContentFilters) { | ||
| pipeline.push( | ||
| { | ||
| $match: { | ||
| ...matchFilter, | ||
| ...searchFilter, | ||
| ...releaseFilter, | ||
| ...assigneeFilter, | ||
| }, | ||
| }, | ||
| { $limit: limit + 1 } | ||
| ); | ||
| } | ||
|
|
||
| pipeline.push({ $unset: 'groupHash' }); | ||
|
|
||
| const cursor = this.getCollection(this.TYPES.DAILY_EVENTS).aggregate(pipeline); | ||
| const result = await cursor.toArray(); | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no usages. Where is it used?