Remove Realtime Database metrics for game list cache.
경기 일정 캐시의 적중률(Hit/Miss)을 RTDB에 기록하던 로직을 제거
This commit is contained in:
parent
6145af7159
commit
98502916de
@ -1,5 +1,3 @@
|
|||||||
import { ServerValue } from "firebase-admin/database";
|
|
||||||
import { rtdb } from "../firebase.js";
|
|
||||||
import {
|
import {
|
||||||
fetchGameList,
|
fetchGameList,
|
||||||
LEAGUE_CODES,
|
LEAGUE_CODES,
|
||||||
@ -27,25 +25,6 @@ function memGet(key: string): GameListResult | null {
|
|||||||
return e.data;
|
return e.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function todayYmd(): string {
|
|
||||||
const n = new Date();
|
|
||||||
return `${n.getFullYear()}${String(n.getMonth() + 1).padStart(2, "0")}${String(n.getDate()).padStart(2, "0")}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 메모리 캐시 hit/miss 카운터를 RTDB에 기록한다.
|
|
||||||
*
|
|
||||||
* 경로: `/metrics/gameListCache/{YYYYMMDD}/{hit|miss}` — 일자별 버킷.
|
|
||||||
* 요청 지연을 막기 위해 await 하지 않고 fire-and-forget으로 처리하고,
|
|
||||||
* 오류는 삼킨다(메트릭 실패가 서비스 실패로 이어지면 안 됨).
|
|
||||||
*/
|
|
||||||
function recordCacheMetric(kind: "hit" | "miss"): void {
|
|
||||||
rtdb
|
|
||||||
.ref(`metrics/gameListCache/${todayYmd()}/${kind}`)
|
|
||||||
.set(ServerValue.increment(1))
|
|
||||||
.catch(() => undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
function memSet(key: string, data: GameListResult): void {
|
function memSet(key: string, data: GameListResult): void {
|
||||||
if (memCache.size >= MEM_MAX) {
|
if (memCache.size >= MEM_MAX) {
|
||||||
const oldest = memCache.keys().next().value;
|
const oldest = memCache.keys().next().value;
|
||||||
@ -70,11 +49,7 @@ export async function getGameList(
|
|||||||
const key = `${dateStr}|${resolvedSeries ?? ""}|${resolvedLeague ?? ""}`;
|
const key = `${dateStr}|${resolvedSeries ?? ""}|${resolvedLeague ?? ""}`;
|
||||||
|
|
||||||
const hit = memGet(key);
|
const hit = memGet(key);
|
||||||
if (hit) {
|
if (hit) return hit;
|
||||||
recordCacheMetric("hit");
|
|
||||||
return hit;
|
|
||||||
}
|
|
||||||
recordCacheMetric("miss");
|
|
||||||
|
|
||||||
const result = await fetchGameList({
|
const result = await fetchGameList({
|
||||||
date,
|
date,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user