diff --git a/src/graphql/operations/plugins.ts b/src/graphql/operations/plugins.ts index e8a477f4..5ba7de55 100644 --- a/src/graphql/operations/plugins.ts +++ b/src/graphql/operations/plugins.ts @@ -1,14 +1,23 @@ -import { spaces } from '../../helpers/spaces'; +import { capture } from '@snapshot-labs/snapshot-sentry'; +import db from '../../helpers/mysql'; -export default function () { - const plugins = {}; - Object.values(spaces).forEach((space: any) => { - Object.keys(space.plugins || {}).forEach(plugin => { - plugins[plugin] = (plugins[plugin] || 0) + 1; - }); - }); - return Object.entries(plugins).map(network => ({ - id: network[0], - spacesCount: network[1] - })); +export default async function () { + const query = ` + SELECT s.name as id, count(s.name) as spacesCount + FROM + spaces, + JSON_TABLE( + JSON_KEYS(settings, '$.plugins'), + '$[*]' COLUMNS (name VARCHAR(255) PATH '$') + ) s + GROUP BY s.name + ORDER BY spacesCount DESC; + `; + + try { + return await db.queryAsync(query); + } catch (e: any) { + capture(e); + return Promise.reject(new Error('request failed')); + } }