Fix: strictly use active flows for online status (ignore dummy summaries)

This commit is contained in:
ypratama committed 2026-09-07 11:43:24 +07:00
1 parent f7ebd7a5c5
commit 068435ffb9
1 file changed
+3 -4
+3 -4
View File
@@ -89,7 +89,7 @@ export async function fetchAgentsFromMongo(
} }
// 3. Optimize status check and last seen per agent using parallel indexed queries // 3. Optimize status check and last seen per agent using parallel indexed queries
const twentyFourHoursAgo = new Date(Date.now() - 24 * 3600000); const fifteenMinutesAgoQuery = new Date(Date.now() - 15 * 60000);
const agentResults = await Promise.all( const agentResults = await Promise.all(
agentSource.map(async (item: any, idx: number) => { agentSource.map(async (item: any, idx: number) => {
@@ -99,7 +99,7 @@ export async function fetchAgentsFromMongo(
// Execute status checks for active flow, latest flow, and latest summary in parallel // Execute status checks for active flow, latest flow, and latest summary in parallel
const [activeFlow, latestFlow, latestSummary] = await Promise.all([ const [activeFlow, latestFlow, latestSummary] = await Promise.all([
db.collection('flows').findOne( db.collection('flows').findOne(
{ agent_uuid: uuid, timestamp: { $gte: twentyFourHoursAgo } }, { agent_uuid: uuid, timestamp: { $gte: fifteenMinutesAgoQuery } },
{ projection: { _id: 1 } } { projection: { _id: 1 } }
), ),
db.collection('flows').findOne( db.collection('flows').findOne(
@@ -135,8 +135,7 @@ export async function fetchAgentsFromMongo(
} }
} }
const fifteenMinutesAgo = new Date(Date.now() - 15 * 60000); const isOnline = !!activeFlow;
const isOnline = lastSeenDate ? lastSeenDate >= fifteenMinutesAgo : !!activeFlow;
let statusHuman = 'No Flows Detected'; let statusHuman = 'No Flows Detected';
if (lastSeenDate) { if (lastSeenDate) {