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:
@@ -44,8 +44,10 @@ import { isAlbumVisibleOv } from '../shared/album-visibility';
|
||||
import {
|
||||
OV_LIKE_BATCH_COMMITTED,
|
||||
OV_PHOTO_APPLIED,
|
||||
OV_VISIT_COUNTED,
|
||||
type LikeBatchCommittedEvent,
|
||||
type PhotoAppliedEvent,
|
||||
type VisitCountedEvent,
|
||||
} from './ov-events';
|
||||
|
||||
/** likes.burst 合并窗口毫秒(惰性读 env,0=逐批即时广播;e2e 可调)。 */
|
||||
@@ -227,6 +229,17 @@ export class RealtimeGateway implements OnModuleDestroy {
|
||||
pending.originBatchIds.push(event.batchId);
|
||||
}
|
||||
|
||||
/** 浏览已计入 → 原样转发契约 stats.updated 消息到相册房间(Task 8)。 */
|
||||
@OnEvent(OV_VISIT_COUNTED)
|
||||
onVisitCounted(event: VisitCountedEvent): void {
|
||||
this.sendToRoom(event.albumId, {
|
||||
type: 'stats.updated',
|
||||
albumId: event.albumId,
|
||||
viewCount: event.viewCount,
|
||||
countVersion: event.statVersion,
|
||||
});
|
||||
}
|
||||
|
||||
/** 副本照片可见性应用 → 原样转发契约 photo.* 消息到相册房间。 */
|
||||
@OnEvent(OV_PHOTO_APPLIED)
|
||||
onPhotoApplied(event: PhotoAppliedEvent): void {
|
||||
|
||||
Reference in New Issue
Block a user