From b585a9a72167d5f803c65a64722ba2bc8889882a Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Thu, 26 Sep 2024 18:47:36 +0400 Subject: [PATCH] uberf-8294: do not upgrade stale workspaces (#6748) Signed-off-by: Alexey Zinoviev --- server/account/src/operations.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/account/src/operations.ts b/server/account/src/operations.ts index b9789ed40f..d33659ab34 100644 --- a/server/account/src/operations.ts +++ b/server/account/src/operations.ts @@ -1017,7 +1017,8 @@ export async function listWorkspacesByAccount (db: Db, email: string): Promise + upToVersion?: Data, + visitedSince?: number ): Promise { const regionQuery = region === '' ? { $or: [{ region: { $exists: false } }, { region: '' }] } : { region } const query: Filter['$and'] = [ @@ -1039,6 +1040,10 @@ export async function countWorkspacesInRegion ( }) } + if (visitedSince !== undefined) { + query.push({ lastVisit: { $gt: visitedSince } }) + } + return await db.collection(WORKSPACE_COLLECTION).countDocuments({ $and: query }) @@ -1256,7 +1261,7 @@ export async function workerHandshake ( const workspacesCnt = await ctx.with( 'count-workspaces-in-region', {}, - async (ctx) => await countWorkspacesInRegion(db, region, version) + async (ctx) => await countWorkspacesInRegion(db, region, version, Date.now() - 24 * 60 * 60 * 1000) ) await db.collection(UPGRADE_COLLECTION).insertOne({ @@ -1494,7 +1499,10 @@ export async function getPendingWorkspace ( { $or: [{ mode: 'active' }, { mode: { $exists: false } }] }, - versionQuery + versionQuery, + { + lastVisit: { $gt: Date.now() - 24 * 60 * 60 * 1000 } + } ] }, {