diff --git a/src/helpers/metrics.ts b/src/helpers/metrics.ts index 500a62d9..b3bbe00f 100644 --- a/src/helpers/metrics.ts +++ b/src/helpers/metrics.ts @@ -58,9 +58,13 @@ export default function initMetrics(app: Express) { if (query && operationName) { const definition = parse(query).definitions.find( // @ts-ignore - def => def.name.value === operationName + def => def.name?.value === operationName ); + if (!definition) { + return; + } + // @ts-ignore const types = definition.selectionSet.selections.map(sel => sel.name.value); diff --git a/src/helpers/moderation.ts b/src/helpers/moderation.ts index cd7e9141..315d8ec6 100644 --- a/src/helpers/moderation.ts +++ b/src/helpers/moderation.ts @@ -13,7 +13,7 @@ async function loadModerationData() { flaggedLinks = res?.flaggedLinks; } -async function run() { +export default async function run() { try { await loadModerationData(); consecutiveFailsCount = 0; @@ -28,5 +28,3 @@ async function run() { await snapshot.utils.sleep(5e3); run(); } - -run(); diff --git a/src/helpers/spaces.ts b/src/helpers/spaces.ts index 40fd3c2e..5e9beb0d 100644 --- a/src/helpers/spaces.ts +++ b/src/helpers/spaces.ts @@ -176,7 +176,7 @@ export async function getSpace(id: string) { }; } -async function run() { +export default async function run() { try { await loadSpaces(); await loadSpacesMetrics(); @@ -187,5 +187,3 @@ async function run() { await snapshot.utils.sleep(360e3); run(); } - -run(); diff --git a/src/index.ts b/src/index.ts index 6e5d5cda..a8aff851 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,8 @@ import rateLimit from './helpers/rateLimit'; import log from './helpers/log'; import initMetrics from './helpers/metrics'; import { checkKeycard } from './helpers/keycard'; -import './helpers/moderation'; +import refreshModerationData from './helpers/moderation'; +import refreshSpacesCache from './helpers/spaces'; import './helpers/strategies'; const app = express(); @@ -16,6 +17,8 @@ const PORT = process.env.PORT || 3000; initLogger(app); initMetrics(app); +refreshModerationData(); +refreshSpacesCache(); app.disable('x-powered-by'); app.use(express.json({ limit: '20mb' }));