Fix ping new integer

This commit is contained in:
Owen 2025-08-14 11:11:01 -07:00
parent d5a11edd0c
commit aabfa91f80
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
2 changed files with 11 additions and 6 deletions

View file

@ -7,7 +7,7 @@ import { createNextServer } from "./nextServer";
import { createInternalServer } from "./internalServer"; import { createInternalServer } from "./internalServer";
import { ApiKey, ApiKeyOrg, Session, User, UserOrg } from "@server/db"; import { ApiKey, ApiKeyOrg, Session, User, UserOrg } from "@server/db";
import { createIntegrationApiServer } from "./integrationApiServer"; import { createIntegrationApiServer } from "./integrationApiServer";
import { createHybridClientServer } from "./privateHybridServer.js"; import { createHybridClientServer } from "./hybridServer";
import config from "@server/lib/config"; import config from "@server/lib/config";
async function startServers() { async function startServers() {

View file

@ -1,7 +1,7 @@
import { db } from "@server/db"; import { db } from "@server/db";
import { MessageHandler } from "../ws"; import { MessageHandler } from "../ws";
import { clients, Olm } from "@server/db"; import { clients, Olm } from "@server/db";
import { eq, lt, isNull } from "drizzle-orm"; import { eq, lt, isNull, and, or } from "drizzle-orm";
import logger from "@server/logger"; import logger from "@server/logger";
// Track if the offline checker interval is running // Track if the offline checker interval is running
@ -20,15 +20,20 @@ export const startOlmOfflineChecker = (): void => {
offlineCheckerInterval = setInterval(async () => { offlineCheckerInterval = setInterval(async () => {
try { try {
const twoMinutesAgo = new Date(Date.now() - OFFLINE_THRESHOLD_MS); const twoMinutesAgo = Math.floor((Date.now() - OFFLINE_THRESHOLD_MS) / 1000);
// Find clients that haven't pinged in the last 2 minutes and mark them as offline // Find clients that haven't pinged in the last 2 minutes and mark them as offline
await db await db
.update(clients) .update(clients)
.set({ online: false }) .set({ online: false })
.where( .where(
eq(clients.online, true) && and(
(lt(clients.lastPing, twoMinutesAgo.getTime() / 1000) || isNull(clients.lastPing)) eq(clients.online, true),
or(
lt(clients.lastPing, twoMinutesAgo),
isNull(clients.lastPing)
)
)
); );
} catch (error) { } catch (error) {
@ -72,7 +77,7 @@ export const handleOlmPingMessage: MessageHandler = async (context) => {
await db await db
.update(clients) .update(clients)
.set({ .set({
lastPing: new Date().getTime() / 1000, lastPing: Math.floor(Date.now() / 1000),
online: true, online: true,
}) })
.where(eq(clients.clientId, olm.clientId)); .where(eq(clients.clientId, olm.clientId));