perf(db): Added indexes

This commit is contained in:
2026-02-20 20:31:02 +01:00
parent 5081819281
commit 21ceb9fa26
10 changed files with 50 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
import { IsInt, IsNotEmpty, IsPositive } from "class-validator"; import { IsInt, IsNotEmpty, IsPositive } from "class-validator";
import { ChildEntity, Column, ManyToOne } from "typeorm"; import { ChildEntity, Column, Index, ManyToOne } from "typeorm";
import { ResponseDistanceDonation } from '../responses/ResponseDistanceDonation'; import { ResponseDistanceDonation } from '../responses/ResponseDistanceDonation';
import { Donation } from "./Donation"; import { Donation } from "./Donation";
import { Runner } from "./Runner"; import { Runner } from "./Runner";
@@ -7,8 +7,9 @@ import { Runner } from "./Runner";
/** /**
* Defines the DistanceDonation entity. * Defines the DistanceDonation entity.
* For distanceDonations a donor pledges to donate a certain amount for each kilometer ran by a runner. * For distanceDonations a donor pledges to donate a certain amount for each kilometer ran by a runner.
*/ */
@ChildEntity() @ChildEntity()
@Index(['runner'])
export class DistanceDonation extends Donation { export class DistanceDonation extends Donation {
/** /**
* The donation's associated runner. * The donation's associated runner.

View File

@@ -2,7 +2,7 @@ import {
IsInt, IsInt,
IsPositive IsPositive
} from "class-validator"; } from "class-validator";
import { BeforeInsert, BeforeUpdate, Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; import { BeforeInsert, BeforeUpdate, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { ResponseDonation } from '../responses/ResponseDonation'; import { ResponseDonation } from '../responses/ResponseDonation';
import { Donor } from './Donor'; import { Donor } from './Donor';
@@ -10,9 +10,10 @@ import { Donor } from './Donor';
* Defines the Donation entity. * Defines the Donation entity.
* A donation just associates a donor with a donation amount. * A donation just associates a donor with a donation amount.
* The specifics of the amoun's determination has to be implemented in child classes. * The specifics of the amoun's determination has to be implemented in child classes.
*/ */
@Entity() @Entity()
@TableInheritance({ column: { name: "type", type: "varchar" } }) @TableInheritance({ column: { name: "type", type: "varchar" } })
@Index(['donor'])
export abstract class Donation { export abstract class Donation {
/** /**
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).

View File

@@ -9,18 +9,19 @@ import {
IsString IsString
} from "class-validator"; } from "class-validator";
import { BeforeInsert, BeforeUpdate, Column, Entity, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; import { BeforeInsert, BeforeUpdate, Column, Entity, Index, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { config } from '../../config'; import { config } from '../../config';
import { ResponseParticipant } from '../responses/ResponseParticipant'; import { ResponseParticipant } from '../responses/ResponseParticipant';
import { Address } from "./Address"; import { Address } from "./Address";
/** /**
* Defines the Participant entity. * Defines the Participant entity.
* Participans can donate and therefor be associated with donation entities. * Participans can donate and therefor be associated with donation entities.
*/ */
@Entity() @Entity()
@TableInheritance({ column: { name: "type", type: "varchar" } }) @TableInheritance({ column: { name: "type", type: "varchar" } })
export abstract class Participant { @Index(['email'])
export abstract class Participant {
/** /**
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */

View File

@@ -1,5 +1,5 @@
import { IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; import { IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator";
import { ChildEntity, Column, ManyToOne, OneToMany } from "typeorm"; import { ChildEntity, Column, Index, ManyToOne, OneToMany } from "typeorm";
import { ResponseRunner } from '../responses/ResponseRunner'; import { ResponseRunner } from '../responses/ResponseRunner';
import { DistanceDonation } from "./DistanceDonation"; import { DistanceDonation } from "./DistanceDonation";
import { Participant } from "./Participant"; import { Participant } from "./Participant";
@@ -11,8 +11,9 @@ import { Scan } from "./Scan";
* Defines the runner entity. * Defines the runner entity.
* Runners differ from participants in being able to actually accumulate a ran distance through scans. * Runners differ from participants in being able to actually accumulate a ran distance through scans.
* Runner's get organized in groups. * Runner's get organized in groups.
*/ */
@ChildEntity() @ChildEntity()
@Index(['group'])
export class Runner extends Participant { export class Runner extends Participant {
/** /**
* The runner's associated group. * The runner's associated group.

View File

@@ -6,7 +6,7 @@ import {
IsOptional, IsOptional,
IsPositive IsPositive
} from "class-validator"; } from "class-validator";
import { BeforeInsert, BeforeUpdate, Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm"; import { BeforeInsert, BeforeUpdate, Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { RunnerCardIdOutOfRangeError } from '../../errors/RunnerCardErrors'; import { RunnerCardIdOutOfRangeError } from '../../errors/RunnerCardErrors';
import { ResponseRunnerCard } from '../responses/ResponseRunnerCard'; import { ResponseRunnerCard } from '../responses/ResponseRunnerCard';
import { Runner } from "./Runner"; import { Runner } from "./Runner";
@@ -16,8 +16,10 @@ import { TrackScan } from "./TrackScan";
* Defines the RunnerCard entity. * Defines the RunnerCard entity.
* A runnerCard is a physical representation for a runner. * A runnerCard is a physical representation for a runner.
* It can be associated with a runner to create scans via the scan station's. * It can be associated with a runner to create scans via the scan station's.
*/ */
@Entity() @Entity()
@Index(['runner'])
@Index(['enabled'])
export class RunnerCard { export class RunnerCard {
/** /**
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).

View File

@@ -1,5 +1,5 @@
import { IsNotEmpty } from "class-validator"; import { IsNotEmpty } from "class-validator";
import { ChildEntity, ManyToOne } from "typeorm"; import { ChildEntity, Index, ManyToOne } from "typeorm";
import { ResponseRunnerTeam } from '../responses/ResponseRunnerTeam'; import { ResponseRunnerTeam } from '../responses/ResponseRunnerTeam';
import { RunnerGroup } from "./RunnerGroup"; import { RunnerGroup } from "./RunnerGroup";
import { RunnerOrganization } from "./RunnerOrganization"; import { RunnerOrganization } from "./RunnerOrganization";
@@ -7,8 +7,9 @@ import { RunnerOrganization } from "./RunnerOrganization";
/** /**
* Defines the RunnerTeam entity. * Defines the RunnerTeam entity.
* This usually is a school class or department in a company. * This usually is a school class or department in a company.
*/ */
@ChildEntity() @ChildEntity()
@Index(['parentGroup'])
export class RunnerTeam extends RunnerGroup { export class RunnerTeam extends RunnerGroup {
/** /**

View File

@@ -5,16 +5,19 @@ import {
IsPositive IsPositive
} from "class-validator"; } from "class-validator";
import { BeforeInsert, BeforeUpdate, Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; import { BeforeInsert, BeforeUpdate, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { ResponseScan } from '../responses/ResponseScan'; import { ResponseScan } from '../responses/ResponseScan';
import { Runner } from "./Runner"; import { Runner } from "./Runner";
/** /**
* Defines the Scan entity. * Defines the Scan entity.
* A scan basicly adds a certain distance to a runner's total ran distance. * A scan basicly adds a certain distance to a runner's total ran distance.
*/ */
@Entity() @Entity()
@TableInheritance({ column: { name: "type", type: "varchar" } }) @TableInheritance({ column: { name: "type", type: "varchar" } })
@Index(['runner'])
@Index(['runner', 'created_at'])
@Index(['valid'])
export class Scan { export class Scan {
/** /**
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).

View File

@@ -6,7 +6,7 @@ import {
IsPositive, IsPositive,
IsString IsString
} from "class-validator"; } from "class-validator";
import { BeforeInsert, BeforeUpdate, Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm"; import { BeforeInsert, BeforeUpdate, Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { ResponseScanStation } from '../responses/ResponseScanStation'; import { ResponseScanStation } from '../responses/ResponseScanStation';
import { Track } from "./Track"; import { Track } from "./Track";
import { TrackScan } from "./TrackScan"; import { TrackScan } from "./TrackScan";
@@ -14,8 +14,11 @@ import { TrackScan } from "./TrackScan";
/** /**
* Defines the ScanStation entity. * Defines the ScanStation entity.
* ScanStations get used to create TrackScans for runners based on a scan of their runnerCard. * ScanStations get used to create TrackScans for runners based on a scan of their runnerCard.
*/ */
@Entity() @Entity()
@Index(['track'])
@Index(['prefix'])
@Index(['enabled'])
export class ScanStation { export class ScanStation {
/** /**
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).

View File

@@ -6,7 +6,7 @@ import {
IsPositive IsPositive
} from "class-validator"; } from "class-validator";
import { ChildEntity, Column, ManyToOne } from "typeorm"; import { ChildEntity, Column, Index, ManyToOne } from "typeorm";
import { ResponseTrackScan } from '../responses/ResponseTrackScan'; import { ResponseTrackScan } from '../responses/ResponseTrackScan';
import { RunnerCard } from "./RunnerCard"; import { RunnerCard } from "./RunnerCard";
import { Scan } from "./Scan"; import { Scan } from "./Scan";
@@ -16,8 +16,13 @@ import { Track } from "./Track";
/** /**
* Defines the TrackScan entity. * Defines the TrackScan entity.
* A track scan usaually get's generated by a scan station. * A track scan usaually get's generated by a scan station.
*/ */
@ChildEntity() @ChildEntity()
@Index(['track'])
@Index(['card'])
@Index(['station'])
@Index(['timestamp'])
@Index(['station', 'timestamp'])
export class TrackScan extends Scan { export class TrackScan extends Scan {
/** /**
* The scan's associated track. * The scan's associated track.

View File

@@ -1,5 +1,5 @@
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUrl, IsUUID } from "class-validator"; import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUrl, IsUUID } from "class-validator";
import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm"; import { ChildEntity, Column, Index, JoinTable, ManyToMany, OneToMany } from "typeorm";
import { config } from '../../config'; import { config } from '../../config';
import { ResponsePrincipal } from '../responses/ResponsePrincipal'; import { ResponsePrincipal } from '../responses/ResponsePrincipal';
import { ResponseUser } from '../responses/ResponseUser'; import { ResponseUser } from '../responses/ResponseUser';
@@ -8,12 +8,13 @@ import { Principal } from './Principal';
import { UserAction } from './UserAction'; import { UserAction } from './UserAction';
import { UserGroup } from './UserGroup'; import { UserGroup } from './UserGroup';
/** /**
* Defines the User entity. * Defines the User entity.
* Users are the ones that can use the "admin" webui and do stuff in the backend. * Users are the ones that can use the "admin" webui and do stuff in the backend.
*/ */
@ChildEntity() @ChildEntity()
export class User extends Principal { @Index(['enabled'])
export class User extends Principal {
/** /**
* The user's uuid. * The user's uuid.
* Mainly gets used as a per-user salt for the password hash. * Mainly gets used as a per-user salt for the password hash.