Skip to content

Commit

Permalink
fix: cache result for 2 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Oct 8, 2024
1 parent b1718db commit 00d8acd
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/graphql/operations/options.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import snapshot from '@snapshot-labs/snapshot.js';
import { capture } from '@snapshot-labs/snapshot-sentry';
import log from '../../helpers/log';
import db from '../../helpers/mysql';

export default async function (_, args) {
const RUN_INTERVAL = 12e3;

let options = [];

export default async function () {
return options;
}

async function loadOptions() {
options = await db.queryAsync('SELECT s.* FROM options s');
}

async function run() {
try {
return await db.queryAsync('SELECT s.* FROM options s');
log.info('[options] Start options refresh');
await loadOptions();
log.info(`[options] ${options.length} options reloaded`);
log.info('[options] End options refresh');
} catch (e: any) {
log.error(`[graphql] options, ${JSON.stringify(e)}`);
capture(e, { args });
return Promise.reject(new Error('request failed'));
capture(e);
log.error(`[options] failed to refresh options, ${JSON.stringify(e)}`);
}
await snapshot.utils.sleep(RUN_INTERVAL);
run();
}

run();

0 comments on commit 00d8acd

Please sign in to comment.