Skip to content

Commit

Permalink
fix: get network data from DB directly
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Oct 18, 2023
1 parent 6021043 commit 90a83e6
Showing 1 changed file with 18 additions and 10 deletions.
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 => ({
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;
`;

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

0 comments on commit 90a83e6

Please sign in to comment.