Revert "Merge pull request 'Complete Housekeeping migration and /ase cutover' (#52) from codex/housekeeping-complete into main"
This reverts commit488b6e57c4, reversing changes made tob506b4499a.
This commit is contained in:
1 parent
488b6e57c4
commit
b1ddda66ff
802 files changed
+61370
-76659
No files matched your search
@@ -1,40 +1,41 @@
|
||||
import "server-only";
|
||||
|
||||
import { count, desc, eq } from "drizzle-orm";
|
||||
import type { OnlineUser } from "@/components/admin/dashboard";
|
||||
import { db, User } from "@/lib/db";
|
||||
|
||||
interface OpsOnlineUserRow {
|
||||
readonly id: number;
|
||||
readonly username: string;
|
||||
readonly look: string;
|
||||
readonly lastOnline: number;
|
||||
}
|
||||
/** Shared online roster used by CommandoCentrum (and linked from other ops hubs). */
|
||||
export async function fetchOpsOnlineUsers(
|
||||
limit = 40,
|
||||
): Promise<{ count: number; users: OnlineUser[] }> {
|
||||
const [countRow, onlineUsersRaw] = await Promise.all([
|
||||
db
|
||||
.select({ total: count() })
|
||||
.from(User)
|
||||
.where(eq(User.online, "1"))
|
||||
.then((rows) => rows[0]?.total ?? 0)
|
||||
.catch(() => 0),
|
||||
db
|
||||
.select({
|
||||
id: User.id,
|
||||
username: User.username,
|
||||
look: User.look,
|
||||
lastOnline: User.lastOnline,
|
||||
})
|
||||
.from(User)
|
||||
.where(eq(User.online, "1"))
|
||||
.orderBy(desc(User.lastOnline))
|
||||
.limit(limit)
|
||||
.then((rows) => rows)
|
||||
.catch(
|
||||
() =>
|
||||
[] as Array<{
|
||||
id: number;
|
||||
username: string;
|
||||
look: string;
|
||||
lastOnline: number;
|
||||
}>,
|
||||
),
|
||||
]);
|
||||
|
||||
function loadOnlineCount(): Promise<number> {
|
||||
return db
|
||||
.select({ total: count() })
|
||||
.from(User)
|
||||
.where(eq(User.online, "1"))
|
||||
.then((rows) => rows[0]?.total ?? 0);
|
||||
}
|
||||
|
||||
function loadOnlineRows(limit: number): Promise<OpsOnlineUserRow[]> {
|
||||
return db
|
||||
.select({
|
||||
id: User.id,
|
||||
username: User.username,
|
||||
look: User.look,
|
||||
lastOnline: User.lastOnline,
|
||||
})
|
||||
.from(User)
|
||||
.where(eq(User.online, "1"))
|
||||
.orderBy(desc(User.lastOnline))
|
||||
.limit(limit)
|
||||
.then((rows) => rows);
|
||||
}
|
||||
|
||||
function onlineRoster(countRow: number, onlineUsersRaw: OpsOnlineUserRow[]) {
|
||||
const users: OnlineUser[] = onlineUsersRaw.map((u) => ({
|
||||
id: u.id,
|
||||
username: u.username,
|
||||
@@ -46,25 +47,3 @@ function onlineRoster(countRow: number, onlineUsersRaw: OpsOnlineUserRow[]) {
|
||||
|
||||
return { count: countRow, users };
|
||||
}
|
||||
|
||||
/** Fail-aware roster for guarded System workflows. */
|
||||
export async function fetchOpsOnlineUsersStrict(
|
||||
limit = 40,
|
||||
): Promise<{ count: number; users: OnlineUser[] }> {
|
||||
const [countRow, onlineUsersRaw] = await Promise.all([
|
||||
loadOnlineCount(),
|
||||
loadOnlineRows(limit),
|
||||
]);
|
||||
return onlineRoster(countRow, onlineUsersRaw);
|
||||
}
|
||||
|
||||
/** Shared tolerant roster used by the legacy CommandoCentrum. */
|
||||
export async function fetchOpsOnlineUsers(
|
||||
limit = 40,
|
||||
): Promise<{ count: number; users: OnlineUser[] }> {
|
||||
const [countRow, onlineUsersRaw] = await Promise.all([
|
||||
loadOnlineCount().catch(() => 0),
|
||||
loadOnlineRows(limit).catch(() => []),
|
||||
]);
|
||||
return onlineRoster(countRow, onlineUsersRaw);
|
||||
}
|
||||
Reference in new issue
Block a user