Skip to content

Commit

Permalink
BC-7179 - add missing indexes (#4952)
Browse files Browse the repository at this point in the history
* replace the old compound index on the studentId and homeworkId fields with the new one that checks for the existence of the studentId field

* add indexes to the contextId and contextType fields in the boardnodes entity

* add index on the createdAt field for the deletion request entity

* add more indexes for the File entity

* add index for the contents.user field in the Lesson entity

* add indexes for the creatorId and updaterId fields in the News entity

* add indexes for the teamMembers and courseGroupId fields in the Submission entity

* remove contents.user index as mikro-orm cannot make one this way

* move index declaration to class level

* change compound index to a separate fields indexes
  • Loading branch information
bn-pass authored and bergatco committed May 6, 2024
1 parent ee9d07e commit c78fea4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface DeletionRequestEntityProps {

@Entity({ tableName: 'deletionrequests' })
@Unique({ properties: ['targetRefId', 'targetRefDomain'] })
@Index({ properties: ['createdAt'] })
export class DeletionRequestEntity extends BaseEntityWithTimestamps {
@Property()
@Index({ options: { expireAfterSeconds: SECONDS_OF_90_DAYS } })
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/modules/files/entity/file.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export interface FileEntityProps {
@Index({ options: { 'permissions.refId': 1 } })
export class FileEntity extends BaseEntityWithTimestamps {
@Property({ nullable: true })
@Index()
deletedAt?: Date;

// you have to set the type explicitly to boolean, otherwise metadata will be wrong
@Property({ type: 'boolean' })
@Index()
deleted = false;

// you have to set the type explicitly to boolean, otherwise metadata will be wrong
Expand Down Expand Up @@ -95,6 +97,7 @@ export class FileEntity extends BaseEntityWithTimestamps {
}

@Enum({ nullable: false })
@Index()
refOwnerModel: FileOwnerModel;

@Property({ fieldName: 'creator', nullable: true })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, Property } from '@mikro-orm/core';
import { Entity, Index, Property } from '@mikro-orm/core';
import { ObjectId } from '@mikro-orm/mongodb';
import {
AnyBoardDo,
Expand All @@ -13,6 +13,8 @@ import { BoardDoBuilder, BoardNodeType } from './types';

// TODO Use an abstract base class for root nodes that have a contextId and a contextType. Multiple STI abstract base classes are blocked by MikroORM 6.1.2 (issue #3745)
@Entity({ discriminatorValue: BoardNodeType.COLUMN_BOARD })
@Index({ properties: ['_contextId'] })
@Index({ properties: ['_contextType'] })
export class ColumnBoardNode extends BoardNode implements LearnroomElement {
constructor(props: ColumnBoardNodeProps) {
super(props);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, Property } from '@mikro-orm/core';
import { Entity, Index, Property } from '@mikro-orm/core';
import { ObjectId } from '@mikro-orm/mongodb';
import {
type AnyBoardDo,
Expand All @@ -12,6 +12,8 @@ import { type BoardDoBuilder, BoardNodeType } from '../types';

// TODO Use an abstract base class for root nodes that have a contextId and a contextType. Multiple STI abstract base classes are blocked by MikroORM 6.1.2 (issue #3745)
@Entity({ discriminatorValue: BoardNodeType.MEDIA_BOARD })
@Index({ properties: ['_contextId'] })
@Index({ properties: ['_contextType'] })
export class MediaBoardNode extends BoardNode {
constructor(props: RootBoardNodeProps) {
super(props);
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/shared/domain/entity/news.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ export abstract class News extends BaseEntityWithTimestamps {
school!: SchoolEntity;

@ManyToOne('User', { fieldName: 'creatorId', nullable: true })
@Index()
creator?: User;

@ManyToOne('User', { fieldName: 'updaterId', nullable: true })
@Index()
updater?: User;

permissions: string[] = [];
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/shared/domain/entity/submission.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export interface SubmissionProperties {

@Entity({ tableName: 'submissions' })
@Index({ properties: ['student', 'teamMembers'] })
@Unique({ properties: ['student', 'task'] })
@Unique({
properties: ['student', 'task'],
options: { partialFilterExpression: { studentId: { $exists: true } } },
})
export class Submission extends BaseEntityWithTimestamps {
@ManyToOne(() => SchoolEntity, { fieldName: 'schoolId' })
@Index()
Expand All @@ -37,9 +40,11 @@ export class Submission extends BaseEntityWithTimestamps {
student?: User;

@ManyToOne('CourseGroup', { fieldName: 'courseGroupId', nullable: true })
@Index()
courseGroup?: CourseGroup;

@ManyToMany('User', undefined, { fieldName: 'teamMembers' })
@Index()
teamMembers = new Collection<User>(this);

@Property({ nullable: true })
Expand Down

0 comments on commit c78fea4

Please sign in to comment.