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 plugins data from DB directly #721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 21 additions & 12 deletions src/graphql/operations/plugins.ts
Original file line number Diff line number Diff line change
@@ -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'));
}
}