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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
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 { DistanceDonation } from "./DistanceDonation";
import { Participant } from "./Participant";
@@ -11,8 +11,9 @@ import { Scan } from "./Scan";
* Defines the runner entity.
* Runners differ from participants in being able to actually accumulate a ran distance through scans.
* Runner's get organized in groups.
*/
*/
@ChildEntity()
@Index(['group'])
export class Runner extends Participant {
/**
* The runner's associated group.

View File

@@ -6,7 +6,7 @@ import {
IsOptional,
IsPositive
} 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 { ResponseRunnerCard } from '../responses/ResponseRunnerCard';
import { Runner } from "./Runner";
@@ -16,8 +16,10 @@ import { TrackScan } from "./TrackScan";
* Defines the RunnerCard entity.
* A runnerCard is a physical representation for a runner.
* It can be associated with a runner to create scans via the scan station's.
*/
*/
@Entity()
@Index(['runner'])
@Index(['enabled'])
export class RunnerCard {
/**
* Autogenerated unique id (primary key).

View File

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

View File

@@ -5,16 +5,19 @@ import {
IsPositive
} 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 { Runner } from "./Runner";
/**
* Defines the Scan entity.
* A scan basicly adds a certain distance to a runner's total ran distance.
*/
*/
@Entity()
@TableInheritance({ column: { name: "type", type: "varchar" } })
@Index(['runner'])
@Index(['runner', 'created_at'])
@Index(['valid'])
export class Scan {
/**
* Autogenerated unique id (primary key).

View File

@@ -6,7 +6,7 @@ import {
IsPositive,
IsString
} 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 { Track } from "./Track";
import { TrackScan } from "./TrackScan";
@@ -14,8 +14,11 @@ import { TrackScan } from "./TrackScan";
/**
* Defines the ScanStation entity.
* ScanStations get used to create TrackScans for runners based on a scan of their runnerCard.
*/
*/
@Entity()
@Index(['track'])
@Index(['prefix'])
@Index(['enabled'])
export class ScanStation {
/**
* Autogenerated unique id (primary key).

View File

@@ -6,7 +6,7 @@ import {
IsPositive
} from "class-validator";
import { ChildEntity, Column, ManyToOne } from "typeorm";
import { ChildEntity, Column, Index, ManyToOne } from "typeorm";
import { ResponseTrackScan } from '../responses/ResponseTrackScan';
import { RunnerCard } from "./RunnerCard";
import { Scan } from "./Scan";
@@ -16,8 +16,13 @@ import { Track } from "./Track";
/**
* Defines the TrackScan entity.
* A track scan usaually get's generated by a scan station.
*/
*/
@ChildEntity()
@Index(['track'])
@Index(['card'])
@Index(['station'])
@Index(['timestamp'])
@Index(['station', 'timestamp'])
export class TrackScan extends Scan {
/**
* 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 { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm";
import { ChildEntity, Column, Index, JoinTable, ManyToMany, OneToMany } from "typeorm";
import { config } from '../../config';
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
import { ResponseUser } from '../responses/ResponseUser';
@@ -8,12 +8,13 @@ import { Principal } from './Principal';
import { UserAction } from './UserAction';
import { UserGroup } from './UserGroup';
/**
* Defines the User entity.
* Users are the ones that can use the "admin" webui and do stuff in the backend.
*/
@ChildEntity()
export class User extends Principal {
/**
* Defines the User entity.
* Users are the ones that can use the "admin" webui and do stuff in the backend.
*/
@ChildEntity()
@Index(['enabled'])
export class User extends Principal {
/**
* The user's uuid.
* Mainly gets used as a per-user salt for the password hash.