diff --git a/api/apps/index.ts b/api/apps/index.ts index 8f0d7ec..0a2b43c 100644 --- a/api/apps/index.ts +++ b/api/apps/index.ts @@ -42,6 +42,7 @@ let apps: ApiApp[] = []; let appsByApiKey: { [apiKey: string]: ApiApp }; let origins = new Set(); let appsInterval: NodeJS.Timeout | null = null; +let appsLastRefreshed: number | null = null; export function stopAppsRefresh() { if (appsInterval) { @@ -92,4 +93,9 @@ function digestApps() { for (const app of apps) { origins.add(app.origin); } + appsLastRefreshed = Date.now(); +} + +export function getAppsLastRefreshed() { + return appsLastRefreshed ?? 0; } diff --git a/api/db/searches-queries.ts b/api/db/searches-queries.ts index b6a40ae..c1863eb 100644 --- a/api/db/searches-queries.ts +++ b/api/db/searches-queries.ts @@ -85,7 +85,7 @@ export async function updateUsedSearch( name: 'upsert_search', text: `insert INTO searches (membership_id, platform_membership_id, destiny_version, query, search_type) values ($1, $2, $3, $4, $5) -on conflict (platform_membership_id, destiny_version, qhash) +on conflict (platform_membership_id, qhash, destiny_version) do update set usage_count = CASE WHEN searches.deleted_at IS NOT NULL THEN 1 ELSE searches.usage_count + 1 END, last_used = current_timestamp, diff --git a/api/index.ts b/api/index.ts index fabeae1..2079a79 100644 --- a/api/index.ts +++ b/api/index.ts @@ -5,7 +5,7 @@ import express from 'express'; import http from 'http'; import morgan from 'morgan'; import vhost from 'vhost'; -import { refreshApps, stopAppsRefresh } from './apps/index.js'; +import { getAppsLastRefreshed, refreshApps, stopAppsRefresh } from './apps/index.js'; import { closeDbPool } from './db/index.js'; import { app as dimGgApp } from './dim-gg/server.js'; import { metrics } from './metrics/index.js'; @@ -114,7 +114,8 @@ function beforeShutdown() { } async function healthCheck() { - return; + // Unhealthy if apps haven't been refreshed in the last 10 minutes + return Date.now() - getAppsLastRefreshed() < 600_000; } createTerminus(server, { healthChecks: {