Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: trigger data refresher manually #731

Merged
merged 3 commits into from
Oct 28, 2023
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: 5 additions & 1 deletion src/helpers/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions src/helpers/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function loadModerationData() {
flaggedLinks = res?.flaggedLinks;
}

async function run() {
export default async function run() {
try {
await loadModerationData();
consecutiveFailsCount = 0;
Expand All @@ -28,5 +28,3 @@ async function run() {
await snapshot.utils.sleep(5e3);
run();
}

run();
4 changes: 1 addition & 3 deletions src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export async function getSpace(id: string) {
};
}

async function run() {
export default async function run() {
try {
await loadSpaces();
await loadSpacesMetrics();
Expand All @@ -187,5 +187,3 @@ async function run() {
await snapshot.utils.sleep(360e3);
run();
}

run();
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ 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();
const PORT = process.env.PORT || 3000;

initLogger(app);
initMetrics(app);
refreshModerationData();
refreshSpacesCache();

app.disable('x-powered-by');
app.use(express.json({ limit: '20mb' }));
Expand Down