mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-22 18:29:19 +02:00
Fix ping new integer
This commit is contained in:
parent
d5a11edd0c
commit
aabfa91f80
2 changed files with 11 additions and 6 deletions
|
@ -7,7 +7,7 @@ import { createNextServer } from "./nextServer";
|
|||
import { createInternalServer } from "./internalServer";
|
||||
import { ApiKey, ApiKeyOrg, Session, User, UserOrg } from "@server/db";
|
||||
import { createIntegrationApiServer } from "./integrationApiServer";
|
||||
import { createHybridClientServer } from "./privateHybridServer.js";
|
||||
import { createHybridClientServer } from "./hybridServer";
|
||||
import config from "@server/lib/config";
|
||||
|
||||
async function startServers() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { db } from "@server/db";
|
||||
import { MessageHandler } from "../ws";
|
||||
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";
|
||||
|
||||
// Track if the offline checker interval is running
|
||||
|
@ -20,15 +20,20 @@ export const startOlmOfflineChecker = (): void => {
|
|||
|
||||
offlineCheckerInterval = setInterval(async () => {
|
||||
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
|
||||
await db
|
||||
.update(clients)
|
||||
.set({ online: false })
|
||||
.where(
|
||||
eq(clients.online, true) &&
|
||||
(lt(clients.lastPing, twoMinutesAgo.getTime() / 1000) || isNull(clients.lastPing))
|
||||
and(
|
||||
eq(clients.online, true),
|
||||
or(
|
||||
lt(clients.lastPing, twoMinutesAgo),
|
||||
isNull(clients.lastPing)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
|
@ -72,7 +77,7 @@ export const handleOlmPingMessage: MessageHandler = async (context) => {
|
|||
await db
|
||||
.update(clients)
|
||||
.set({
|
||||
lastPing: new Date().getTime() / 1000,
|
||||
lastPing: Math.floor(Date.now() / 1000),
|
||||
online: true,
|
||||
})
|
||||
.where(eq(clients.clientId, olm.clientId));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue