Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let apps: ApiApp[] = [];
let appsByApiKey: { [apiKey: string]: ApiApp };
let origins = new Set<string>();
let appsInterval: NodeJS.Timeout | null = null;
let appsLastRefreshed: number | null = null;

export function stopAppsRefresh() {
if (appsInterval) {
Expand Down Expand Up @@ -92,4 +93,9 @@ function digestApps() {
for (const app of apps) {
origins.add(app.origin);
}
appsLastRefreshed = Date.now();
}

export function getAppsLastRefreshed() {
return appsLastRefreshed ?? 0;
}
2 changes: 1 addition & 1 deletion api/db/searches-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: {
Expand Down