diff --git a/src/lib/actions/agentsMongo.ts b/src/lib/actions/agentsMongo.ts index db7d034..76bb3d6 100644 --- a/src/lib/actions/agentsMongo.ts +++ b/src/lib/actions/agentsMongo.ts @@ -89,7 +89,7 @@ export async function fetchAgentsFromMongo( } // 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( 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 const [activeFlow, latestFlow, latestSummary] = await Promise.all([ db.collection('flows').findOne( - { agent_uuid: uuid, timestamp: { $gte: twentyFourHoursAgo } }, + { agent_uuid: uuid, timestamp: { $gte: fifteenMinutesAgoQuery } }, { projection: { _id: 1 } } ), db.collection('flows').findOne( @@ -135,8 +135,7 @@ export async function fetchAgentsFromMongo( } } - const fifteenMinutesAgo = new Date(Date.now() - 15 * 60000); - const isOnline = lastSeenDate ? lastSeenDate >= fifteenMinutesAgo : !!activeFlow; + const isOnline = !!activeFlow; let statusHuman = 'No Flows Detected'; if (lastSeenDate) {