fix(api): correct champion history and deduplicate stats builds

Apply participant and champion filters before pagination and exclude timeline payloads. Route result statistics through the durable outbox, reuse current fragments, and serialize projection effects without spending retries on contention.

Validated with 716 API tests, 32 isolated Redis integration tests, API typecheck and build, and lint on changed files.
This commit is contained in:
dahyeon committed 2026-11-09 18:40:51 +09:00
1 parent ef141a13d0
commit f2eec479d9
14 files changed
+704 -47

No files matched your search

@@ -8,6 +8,7 @@ import mongoose from 'mongoose';
import { CommunityStatsService } from '../community-stats/community-stats.service';
import { MatchStatsService } from '../community-stats/match-stats.service';
import { ConnectionService } from '../global/database/connection.service';
import { DistributedLockService } from '../global/redis/distributed-lock.service';
import { CompetitionAssignmentProvisioner } from './competition-assignment.provisioner';
import type { CompetitionResultSnapshot } from './competition-result.adapter';
@@ -54,6 +55,7 @@ export class CompetitionOutboxProcessor
private readonly assignmentProvisioner: CompetitionAssignmentProvisioner,
private readonly matchStatsService: MatchStatsService,
private readonly communityStatsService: CommunityStatsService,
private readonly distributedLockService: DistributedLockService,
) {}
public onModuleInit(): void {
@@ -125,7 +127,30 @@ export class CompetitionOutboxProcessor
if (event.type !== 'competition.projection-updated') {
throw new Error(`Unsupported Competition outbox type ${event.type}.`);
}
await this.applyProjectionEffects(event);
// Different revision events can be leased by different API instances.
// Serialize their effects so the next builder can reuse committed stats.
const applied = await this.distributedLockService.runWithRenewedLock(
{
lockKey: `competition:projection-effects:${event.competitionId.toString()}`,
lockExpirationDurationMilliseconds: PROCESSING_LEASE_MS,
lockRenewalIntervalMilliseconds: PROCESSING_LEASE_MS / 3,
},
async () => {
await this.applyProjectionEffects(event);
return true;
},
);
if (!applied) {
// Contention is not a failed delivery and must not exhaust retries.
await OutboxModel.updateOne(leaseFilter(event), {
$set: {
state: 'pending',
availableAt: new Date(Date.now() + DRAIN_INTERVAL_MS),
},
$inc: { attemptCount: -1 },
}).exec();
return;
}
await OutboxModel.updateOne(leaseFilter(event), {
$set: { state: 'published', publishedAt: new Date() },
$unset: { lastError: 1 },