Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/achievements/achievements.seed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AchievementType, AchievementDifficulty } from './entities/achievement.entity';
import { Logger } from '@nestjs/common';

/**
* Seed data for default achievements
Expand Down
8 changes: 7 additions & 1 deletion src/assessment/entities/answer.entity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, VersionColumn } from 'typeorm';
import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, VersionColumn } from 'typeorm';
import { AssessmentAttempt } from './assessment-attempt.entity';
import { Question } from './question.entity';
/**
* Represents the answer entity.
*/
@Entity()
// Composite index for the common "answers of an attempt" lookup and
// the "answer for a given question within an attempt" lookup. Because the
// leading column is `attempt`, this also serves attempt-only filters, so a
// separate single-column index on `attempt` would be redundant.
@Index('IDX_answer_attempt_question', ['attempt', 'question'])
@Index('IDX_answer_question', ['question'])
export class Answer {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
1 change: 0 additions & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { RegisterDto } from './dto/register.dto';
import { RefreshTokenDto } from './dto/refresh-token.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from '../users/entities/user.entity';
import { Tenant } from '../tenancy/entities/tenant.entity';
import { Repository } from 'typeorm';
import * as bcrypt from 'bcrypt';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
Expand Down
4 changes: 4 additions & 0 deletions src/migrations/1599999999999-BaselineSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ export class BaselineSchema1599999999999 implements MigrationInterface {
"attemptId" uuid,
"questionId" uuid
)
`);
await queryRunner.query(`CREATE INDEX idx_answer_attempt_id ON public.answer USING btree ("attemptId")
`);
await queryRunner.query(`CREATE INDEX idx_answer_question_id ON public.answer USING btree ("questionId")
`);
await queryRunner.query(`CREATE TABLE public.archived_data (
id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
Expand Down
29 changes: 29 additions & 0 deletions src/migrations/1756476695000-add-answer-indexes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddAnswerIndexes1756476695000 implements MigrationInterface {
name = 'AddAnswerIndexes1756476695000';

public async up(queryRunner: QueryRunner): Promise<void> {
// Foreign-key / lookup column indexes for the "answer" table.
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_answer_question_id" ON "answer" ("question_id")',
);
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_answer_submission_id" ON "answer" ("submission_id")',
);
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_answer_created_at" ON "answer" ("created_at")',
);
// Composite index for the common "answers for a submission, by question" lookup.
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_answer_submission_id_question_id" ON "answer" ("submission_id", "question_id")',
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('DROP INDEX IF EXISTS "IDX_answer_submission_id_question_id"');
await queryRunner.query('DROP INDEX IF EXISTS "IDX_answer_created_at"');
await queryRunner.query('DROP INDEX IF EXISTS "IDX_answer_submission_id"');
await queryRunner.query('DROP INDEX IF EXISTS "IDX_answer_question_id"');
}
}
4 changes: 2 additions & 2 deletions src/payments/providers/payment-provider.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PaymentProviderService {
userId: string,
amount: number,
currency: string,
metadata: Record<string, unknown> = {},
_metadata: Record<string, unknown> = {},
): Promise<ChargeResult> {
// TODO: replace with real Stripe call:
// const intent = await stripe.paymentIntents.create({ amount: Math.round(amount * 100), currency, ... });
Expand All @@ -58,7 +58,7 @@ export class PaymentProviderService {
userId: string,
amount: number,
currency: string,
metadata: Record<string, unknown> = {},
_metadata: Record<string, unknown> = {},
): Promise<CreditResult> {
// TODO: replace with real Stripe call:
// const credit = await stripe.customers.createBalanceTransaction(customerId, { amount: -Math.round(amount * 100), currency });
Expand Down
Loading