Skip to content

Commit

Permalink
perf(assignments-service): Better assignment sort index
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Nov 15, 2023
1 parent 5d0ec5f commit c51514b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion services/apps/assignments/src/assignment/assignment.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,15 @@ export class Assignment {

export type AssignmentDocument = Doc<Assignment>;

export const AssignmentSchema = SchemaFactory.createForClass(Assignment);
export const ASSIGNMENT_SORT = {
title: 1,
} as const;

export const ASSIGNMENT_COLLATION = {
locale: 'en',
numericOrdering: true,
} as const;

export const AssignmentSchema = SchemaFactory.createForClass(Assignment)
.index(ASSIGNMENT_SORT, {collation: ASSIGNMENT_COLLATION})
;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {InjectModel} from '@nestjs/mongoose';
import {FilterQuery, Model, Types, UpdateQuery} from 'mongoose';
import {generateToken} from '../utils';
import {CreateAssignmentDto, ReadAssignmentDto, ReadTaskDto, UpdateAssignmentDto} from './assignment.dto';
import {Assignment, AssignmentDocument, Task} from './assignment.schema';
import {Assignment, ASSIGNMENT_COLLATION, ASSIGNMENT_SORT, AssignmentDocument, Task} from './assignment.schema';
import {MemberService} from "@app/member";

@Injectable()
Expand Down Expand Up @@ -42,9 +42,9 @@ export class AssignmentService {
}

async findAll(where: FilterQuery<Assignment> = {}): Promise<AssignmentDocument[]> {
return this.model.find(where).sort({title: 1}).collation({
locale: 'en',
numericOrdering: true,
return this.model.find(where, undefined,{
sort: ASSIGNMENT_SORT,
collation: ASSIGNMENT_COLLATION,
}).exec();
}

Expand Down

0 comments on commit c51514b

Please sign in to comment.