From 031d89101e670ac7874730fa6f73baffecd84262 Mon Sep 17 00:00:00 2001 From: dsutanto Date: Mon, 20 Jul 2026 14:10:40 +0700 Subject: [PATCH] Fix fow Top Protocol graph in Dashboard --- backend/routes/dashboard/apps.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/routes/dashboard/apps.js b/backend/routes/dashboard/apps.js index 059e886..70bd617 100644 --- a/backend/routes/dashboard/apps.js +++ b/backend/routes/dashboard/apps.js @@ -1,6 +1,6 @@ const express = require('express'); const router = express.Router(); -const { AppStat, ProtocolStat, AppCategoryStat, LookupApp } = require('../../models/Schemas'); +const { AppStat, ProtocolStat, AppCategoryStat, LookupApp, Flow } = require('../../models/Schemas'); const { getTimeFilter, getBaseFilter } = require('./helpers'); // GET /api/dashboard/apps @@ -44,17 +44,18 @@ router.get('/protocols', async (req, res) => { const base = getBaseFilter(req, timeFilter); const pipeline = [ - { $match: base }, + { $match: { ...base, protocol: { $ne: null, $ne: '' } } }, { $group: { - _id: '$protocol_label', + _id: '$protocol', download: { $sum: '$download' }, upload: { $sum: '$upload' }, - flows: { $sum: '$flows' }, + flows: { $sum: 1 }, }}, - { $sort: { download: -1 } } + { $sort: { download: -1 } }, + { $limit: 20 } ]; - const result = await ProtocolStat.aggregate(pipeline); + const result = await Flow.aggregate(pipeline); const formatted = result.map(r => ({ protocol_label: r._id, download: r.download || 0,