perf: add bans.user_id index, Redis cache layer, rate-limit improvements, radio contest/giveaway columns, and tests
- Add DB index on bans.user_id to speed up per-request ban lookups (migration 0008) - Replace in-process rate limiter with Redis-backed implementation with in-memory fallback - Add Redis caching layer for site settings with TTL invalidation (migration 0009) - Add rate limiting to resetPassword to prevent token brute-force attacks - Update all rateLimit callers to await the now-async function - Flesh out RadioContests and RadioGiveaways models with title, description, prize, date, and winner columns - Update radio contest/giveaway pages to display new fields - Add tests for rate limiter (4 tests) and password-reset actions (3 tests) - Add REDIS_URL environment variable (optional, falls back to in-memory)
This commit is contained in:
1 parent
43c0ba6614
commit
5c638cd6bc
25 files changed
+449
-63
No files matched your search
@@ -0,0 +1,4 @@
|
||||
-- 0008_add_bans_user_id_index.sql
|
||||
-- Adds an index on bans.user_id to speed up ban lookups by user (used by
|
||||
-- the access guard on every page request for logged-in users).
|
||||
CREATE INDEX IF NOT EXISTS `bans_user_id_index` ON `bans` (`user_id`);
|
||||
@@ -0,0 +1,29 @@
|
||||
-- 0009_radio_contests_giveaways_columns.sql
|
||||
-- Fills in the empty RadioContests and RadioGiveaways tables with meaningful
|
||||
-- columns. These tables were created in migration 0004 with only id/timestamps.
|
||||
|
||||
ALTER TABLE `radio_contests`
|
||||
ADD COLUMN `title` VARCHAR(255) NOT NULL AFTER `id`,
|
||||
ADD COLUMN `description` TEXT NULL AFTER `title`,
|
||||
ADD COLUMN `prize` VARCHAR(255) NULL AFTER `description`,
|
||||
ADD COLUMN `start_date` TIMESTAMP(0) NULL AFTER `prize`,
|
||||
ADD COLUMN `end_date` TIMESTAMP(0) NULL AFTER `start_date`,
|
||||
ADD COLUMN `winner_id` BIGINT UNSIGNED NULL AFTER `end_date`,
|
||||
ADD COLUMN `is_active` BOOLEAN NOT NULL DEFAULT true AFTER `winner_id`,
|
||||
ADD COLUMN `created_by` BIGINT UNSIGNED NULL AFTER `is_active`,
|
||||
MODIFY COLUMN `created_at` TIMESTAMP(0) NULL AFTER `created_by`,
|
||||
MODIFY COLUMN `updated_at` TIMESTAMP(0) NULL AFTER `created_at`;
|
||||
|
||||
ALTER TABLE `radio_giveaways`
|
||||
ADD COLUMN `title` VARCHAR(255) NOT NULL AFTER `id`,
|
||||
ADD COLUMN `description` TEXT NULL AFTER `title`,
|
||||
ADD COLUMN `prize` VARCHAR(255) NULL AFTER `description`,
|
||||
ADD COLUMN `prize_amount` INT NOT NULL DEFAULT 0 AFTER `prize`,
|
||||
ADD COLUMN `prize_currency` VARCHAR(50) NULL AFTER `prize_amount`,
|
||||
ADD COLUMN `start_date` TIMESTAMP(0) NULL AFTER `prize_currency`,
|
||||
ADD COLUMN `end_date` TIMESTAMP(0) NULL AFTER `start_date`,
|
||||
ADD COLUMN `winner_id` BIGINT UNSIGNED NULL AFTER `end_date`,
|
||||
ADD COLUMN `is_active` BOOLEAN NOT NULL DEFAULT true AFTER `winner_id`,
|
||||
ADD COLUMN `created_by` BIGINT UNSIGNED NULL AFTER `is_active`,
|
||||
MODIFY COLUMN `created_at` TIMESTAMP(0) NULL AFTER `created_by`,
|
||||
MODIFY COLUMN `updated_at` TIMESTAMP(0) NULL AFTER `created_at`;
|
||||
+25
-6
@@ -92,6 +92,7 @@ model Ban {
|
||||
type bans_type @default(account)
|
||||
cfhTopic Int @default(-1) @map("cfh_topic")
|
||||
|
||||
@@index([userId])
|
||||
@@map("bans")
|
||||
}
|
||||
|
||||
@@ -2121,17 +2122,35 @@ model RadioHistory {
|
||||
}
|
||||
|
||||
model RadioContests {
|
||||
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
createdAt DateTime? @map("created_at") @db.Timestamp(0)
|
||||
updatedAt DateTime? @map("updated_at") @db.Timestamp(0)
|
||||
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
title String @db.VarChar(255)
|
||||
description String? @db.Text
|
||||
prize String? @db.VarChar(255)
|
||||
startDate DateTime? @map("start_date") @db.Timestamp(0)
|
||||
endDate DateTime? @map("end_date") @db.Timestamp(0)
|
||||
winnerId BigInt? @map("winner_id") @db.UnsignedBigInt
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdBy BigInt? @map("created_by") @db.UnsignedBigInt
|
||||
createdAt DateTime? @map("created_at") @db.Timestamp(0)
|
||||
updatedAt DateTime? @map("updated_at") @db.Timestamp(0)
|
||||
|
||||
@@map("radio_contests")
|
||||
}
|
||||
|
||||
model RadioGiveaways {
|
||||
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
createdAt DateTime? @map("created_at") @db.Timestamp(0)
|
||||
updatedAt DateTime? @map("updated_at") @db.Timestamp(0)
|
||||
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
title String @db.VarChar(255)
|
||||
description String? @db.Text
|
||||
prize String? @db.VarChar(255)
|
||||
prizeAmount Int @default(0) @map("prize_amount")
|
||||
prizeCurrency String? @map("prize_currency") @db.VarChar(50)
|
||||
startDate DateTime? @map("start_date") @db.Timestamp(0)
|
||||
endDate DateTime? @map("end_date") @db.Timestamp(0)
|
||||
winnerId BigInt? @map("winner_id") @db.UnsignedBigInt
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdBy BigInt? @map("created_by") @db.UnsignedBigInt
|
||||
createdAt DateTime? @map("created_at") @db.Timestamp(0)
|
||||
updatedAt DateTime? @map("updated_at") @db.Timestamp(0)
|
||||
|
||||
@@map("radio_giveaways")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user