@@ -359,56 +359,44 @@ function postPluginGraphQL(gqlField, prefix, foreignKey, dtRequest, callback) {
359359
360360// Fetch counts for all plugins. Returns { PREFIX: { objects, events, history } }
361361// or null on failure (fail-open so tabs still render).
362- // Fast path : static JSON (~1KB) when no MAC filter is active .
363- // Filtered path: batched GraphQL aliases when a foreignKey (MAC) is set .
362+ // Unfiltered : static JSON (~1KB pre-computed) .
363+ // MAC-filtered: lightweight REST endpoint (single SQL query) .
364364async function fetchPluginCounts(prefixes) {
365365 if (prefixes.length === 0) return {};
366366
367+ const mac = $("#txtMacFilter").val();
368+ const foreignKey = (mac && mac !== "--") ? mac : null;
369+
367370 try {
368- const mac = $("#txtMacFilter").val();
369- const foreignKey = (mac && mac !== "--") ? mac : null;
370371 let counts = {};
372+ let rows;
371373
372374 if (!foreignKey) {
373- // ---- FAST PATH: lightweight pre-computed JSON ----
375+ // ---- FAST PATH: pre-computed static JSON ----
374376 const stats = await fetchJson('table_plugins_stats.json');
375- for (const row of stats.data) {
376- const p = row.tableName; // 'objects' | 'events' | 'history'
377- const plugin = row.plugin;
378- if (!counts[plugin]) counts[plugin] = { objects: 0, events: 0, history: 0 };
379- counts[plugin][p] = row.cnt;
380- }
377+ rows = stats.data;
381378 } else {
382- // ---- FILTERED PATH: GraphQL with foreignKey ----
379+ // ---- MAC- FILTERED PATH: single SQL via REST endpoint ----
383380 const apiToken = getSetting("API_TOKEN");
384381 const apiBase = getApiBase();
385- const fkOpt = `, foreignKey: "${foreignKey}"`;
386- const fragments = prefixes.map(p => [
387- `${p}_obj: pluginsObjects(options: {plugin: "${p}", page: 1, limit: 1${fkOpt}}) { dbCount }`,
388- `${p}_evt: pluginsEvents(options: {plugin: "${p}", page: 1, limit: 1${fkOpt}}) { dbCount }`,
389- `${p}_hist: pluginsHistory(options: {plugin: "${p}", page: 1, limit: 1${fkOpt}}) { dbCount }`,
390- ].join('\n ')).join('\n ');
391-
392- const query = `query BadgeCounts {\n ${fragments}\n }`;
393382 const response = await $.ajax({
394- method: "POST",
395- url: `${apiBase}/graphql`,
396- headers: { "Authorization": `Bearer ${apiToken}`, "Content-Type": "application/json" },
397- data: JSON.stringify({ query }),
383+ method: "GET",
384+ url: `${apiBase}/plugins/stats?foreignKey=${encodeURIComponent(foreignKey)}`,
385+ headers: { "Authorization": `Bearer ${apiToken}` },
398386 });
399- if (response.errors) {
400- console.error("[plugins] badge GQL errors:", response.errors);
401- return null; // fail-open
402- }
403- for (const p of prefixes) {
404- counts[p] = {
405- objects: response.data[`${p}_obj`]?.dbCount ?? 0,
406- events: response.data[`${p}_evt`]?.dbCount ?? 0,
407- history: response.data[`${p}_hist`]?.dbCount ?? 0,
408- };
387+ if (!response.success) {
388+ console.error("[plugins] /plugins/stats error:", response.error);
389+ return null;
409390 }
391+ rows = response.data;
410392 }
411393
394+ for (const row of rows) {
395+ const p = row.tableName; // 'objects' | 'events' | 'history'
396+ const plugin = row.plugin;
397+ if (!counts[plugin]) counts[plugin] = { objects: 0, events: 0, history: 0 };
398+ counts[plugin][p] = row.cnt;
399+ }
412400 return counts;
413401 } catch (err) {
414402 console.error('[plugins] fetchPluginCounts failed (fail-open):', err);
0 commit comments