fix(api): correct online count in /v1/me/workspace
count distinct members with disconnectedAt is null instead of all presence rows — a member can have many sessions, plus stale rows from prior runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -435,12 +435,16 @@ export const v1Router = new Hono<Env>()
|
||||
const onlineCounts = await db
|
||||
.select({
|
||||
meshId: meshMember.meshId,
|
||||
online: count(presence.memberId),
|
||||
online: sql<number>`count(distinct ${presence.memberId})`,
|
||||
})
|
||||
.from(presence)
|
||||
.innerJoin(meshMember, eq(presence.memberId, meshMember.id))
|
||||
.where(
|
||||
and(inArray(meshMember.meshId, meshIds), isNull(meshMember.revokedAt)),
|
||||
and(
|
||||
inArray(meshMember.meshId, meshIds),
|
||||
isNull(meshMember.revokedAt),
|
||||
isNull(presence.disconnectedAt),
|
||||
),
|
||||
)
|
||||
.groupBy(meshMember.meshId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user