feat(ov): windowed dedup visit counting with retention cleanup

Task 8 (P2): POST /public/albums/{token}/visits with visit_sessions
window dedup (VISIT_WINDOW_MINUTES), requestId idempotent replay
(echoes stored outcome; expired beyond VISIT_REQUEST_TTL_MINUTES
rejected), album_stats viewCount/statVersion authority + outbox_stat_events
views snapshots, WS stats.updated broadcast, visitorId+IP fixed-window
rate limit (VISIT_WINDOW_REQUESTS), and ov CleanupModule scheduler
(setInterval, CLEANUP_INTERVAL_MINUTES) deleting like_batches /
visit_requests / visit_sessions past their windows — totals never
touched. Contract prose aligned to replay semantics; constants
VISIT_WINDOW_REQUESTS / CLEANUP_INTERVAL_MINUTES added.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-18 18:14:01 +08:00
parent 85b2da3db5
commit 1f2a0c658f
14 changed files with 1398 additions and 25 deletions
@@ -0,0 +1,16 @@
// services/api/src/cleanup/ —— ov 互动流水清理模块(P2 Task 8)。仅 ov 入口
// 装配(app-ov.module 显式挑选;cn 入口不感知——cn 侧无互动流水表)。
// CleanupService 同时导出:调度(setInterval,见 cleanup.service.ts 头注)
// 与 runCleanupOnce(e2e 直调断言)。语义边界:仅清 like_batches /
// visit_requests / visit_sessions 超窗口行,累计总数(album_stats、
// photos_ov.likeTotal)永不触碰。
import { Module } from '@nestjs/common';
import { OvPrismaModule } from '../prisma-ov/ov-prisma.module';
import { CleanupService } from './cleanup.service';
@Module({
imports: [OvPrismaModule],
providers: [CleanupService],
exports: [CleanupService],
})
export class CleanupModule {}