Use an epoch number for the clients online to fix query

This commit is contained in:
Owen 2025-08-13 20:26:50 -07:00
parent dc50190dc3
commit 285e24cdc7
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
3 changed files with 4 additions and 4 deletions

View file

@ -513,7 +513,7 @@ export const clients = pgTable("clients", {
megabytesIn: real("bytesIn"),
megabytesOut: real("bytesOut"),
lastBandwidthUpdate: varchar("lastBandwidthUpdate"),
lastPing: varchar("lastPing"),
lastPing: integer("lastPing"),
type: varchar("type").notNull(), // "olm"
online: boolean("online").notNull().default(false),
// endpoint: varchar("endpoint"),

View file

@ -213,7 +213,7 @@ export const clients = sqliteTable("clients", {
megabytesIn: integer("bytesIn"),
megabytesOut: integer("bytesOut"),
lastBandwidthUpdate: text("lastBandwidthUpdate"),
lastPing: text("lastPing"),
lastPing: integer("lastPing"),
type: text("type").notNull(), // "olm"
online: integer("online", { mode: "boolean" }).notNull().default(false),
// endpoint: text("endpoint"),

View file

@ -28,7 +28,7 @@ export const startOfflineChecker = (): void => {
.set({ online: false })
.where(
eq(clients.online, true) &&
(lt(clients.lastPing, twoMinutesAgo.toISOString()) || isNull(clients.lastPing))
(lt(clients.lastPing, twoMinutesAgo.getTime() / 1000) || isNull(clients.lastPing))
);
} catch (error) {
@ -72,7 +72,7 @@ export const handleOlmPingMessage: MessageHandler = async (context) => {
await db
.update(clients)
.set({
lastPing: new Date().toISOString(),
lastPing: new Date().getTime() / 1000,
online: true,
})
.where(eq(clients.clientId, olm.clientId));