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

fix: get network data from DB directly #722

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
28 changes: 18 additions & 10 deletions src/graphql/operations/networks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { spaces } from '../../helpers/spaces';
import { capture } from '@snapshot-labs/snapshot-sentry';
import db from '../../helpers/mysql';

export default function () {
const networks = {};
Object.values(spaces).forEach((space: any) => {
networks[space.network] = networks[space.network] ? networks[space.network] + 1 : 1;
});
return Object.entries(networks).map(network => ({
ChaituVR marked this conversation as resolved.
Show resolved Hide resolved
id: network[0],
spacesCount: network[1]
}));
export default async function () {
const query = `
SELECT
JSON_UNQUOTE(JSON_EXTRACT(settings, '$.network')) as network,
COUNT(name) AS spacesCount
FROM spaces
GROUP BY network
ORDER BY spacesCount DESC;
`;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Takes around 0.5 sec on prod, should be fine?

try {
return (await db.queryAsync(query)).map(v => ({ ...v, id: v.network }));
} catch (e: any) {
capture(e);
return Promise.reject(new Error('request failed'));
}
}