-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Sort area children by leftRightIndex #296
base: develop
Are you sure you want to change the base?
Changes from 3 commits
e51db9e
127faf5
cc0e38d
666fa4c
38515ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { getAreaModel, getMediaModel, getMediaObjectModel } from '../db/index.js | |
import { AreaType } from '../db/AreaTypes' | ||
import { GQLFilter, AreaFilterParams, PathTokenParams, LeafStatusParams, ComparisonFilterParams, StatisticsType, CragsNear, BBoxType } from '../types' | ||
import { getClimbModel } from '../db/ClimbSchema.js' | ||
import { ClimbGQLQueryType } from '../db/ClimbTypes.js' | ||
import { ClimbGQLQueryType, ClimbType } from '../db/ClimbTypes.js' | ||
import { logger } from '../logger.js' | ||
|
||
export default class AreaDataSource extends MongoDataSource<AreaType> { | ||
|
@@ -108,6 +108,12 @@ export default class AreaDataSource extends MongoDataSource<AreaType> { | |
$set: { | ||
'climbs.gradeContext': '$gradeContext' // manually set area's grade context to climb | ||
} | ||
}, | ||
{ | ||
$set: { | ||
climbs: { $sortArray: { input: '$climbs', sortBy: { 'metadata.left_right_index': 1 } } }, | ||
children: { $sortArray: { input: '$children', sortBy: { 'metadata.leftRightIndex': 1 } } } | ||
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. can you confirm 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. Oh yeah you're right! I've not tested this far because it throws a "No such operation as $sortArray" error. 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. What if we did a $lookup for children above this 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.
I thought the query would get too wildly complicated for a small performance gain, whereas the GQL field resolution way in my comment above is more elegant and simpler (but requires an additional query). |
||
} | ||
} | ||
]) | ||
|
||
|
@@ -117,7 +123,7 @@ export default class AreaDataSource extends MongoDataSource<AreaType> { | |
throw new Error(`Area ${uuid.toUUID().toString()} not found.`) | ||
} | ||
|
||
async findManyClimbsByUuids (uuidList: muuid.MUUID[]): Promise<any> { | ||
async findManyClimbsByUuids (uuidList: muuid.MUUID[]): Promise<ClimbType[]> { | ||
const rs = await this.climbModel.find().where('_id').in(uuidList) | ||
return rs | ||
} | ||
|
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.
$sortArray
requires Mongo 5.2 and up. Otherwise we need something like this: https://stackoverflow.com/questions/15388127/mongodb-sort-inner-array