Compare commits

...

8 Commits

Author SHA1 Message Date
Bas950
b25880d4cd chore: release v0.0.29 2024-09-17 09:11:12 +02:00
Bas950
fb06227aeb chore: release v0.0.29 2024-09-17 09:07:58 +02:00
Bas950
ff3d00497b chore: release v0.0.29 2024-09-17 09:07:21 +02:00
Bas950
a06780f85a chore: reduce memory 2024-09-17 09:06:10 +02:00
Bas950
5b1969c7ab chore: release v0.0.28 2024-09-16 23:22:15 +02:00
Bas950
bedd34594c chore: disable ip stuff for now 2024-09-16 23:22:11 +02:00
Bas950
47feaa5c70 chore: release v0.0.27 2024-09-16 22:56:14 +02:00
Bas950
9fb32f53ae chore: reduce batch size 2024-09-16 22:56:10 +02:00
6 changed files with 27 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "@premid/api-master",
"type": "module",
"version": "0.0.26",
"version": "0.0.29",
"private": true,
"description": "PreMiD's api master",
"license": "MPL-2.0",

View File

@@ -23,8 +23,13 @@ export class ClearableGaugeMetric {
this.data.set(key, { value, attributes });
}
clear() {
this.data.clear();
clear({ except }: { except?: string[] }) {
for (const key of this.data.keys()) {
if (except && except.includes(key))
continue;
this.data.delete(key);
}
}
toMetricData(): GaugeMetricData {

View File

@@ -2,7 +2,7 @@ import type { InferInsertModel } from "drizzle-orm";
import { db, onlineUsersIpData } from "../db.js";
import { lookupIp } from "./lookupIp.js";
const batchSize = 10000;
const batchSize = 1000;
export async function insertIpData(
data: Map<string, {
@@ -11,13 +11,14 @@ export async function insertIpData(
}>,
) {
const timestamp = new Date();
const list = Array.from(data.entries());
const list = [...data.keys()];
//* Split into batches of batchSize
for (let i = 0; i < list.length; i += batchSize) {
const batch = list.slice(i, i + batchSize);
const mapped = await Promise.all(batch.map(async ([ip, { presences, sessions }]) => {
const mapped = await Promise.all(batch.map(async (ip) => {
const parsed = await lookupIp(ip);
if (parsed) {
const { presences, sessions } = data.get(ip)!;
return {
ip,
country: parsed.country,

View File

@@ -23,7 +23,7 @@ export async function lookupIp(ip: string): Promise<{ latitude: number; longitud
}
}
let reloading: Promise<void> | undefined;
let reloading: Promise<void> | undefined = Promise.resolve();
let log: debug.Debugger | undefined;
export async function reloadIpLocationApi() {

View File

@@ -37,7 +37,7 @@ export async function updateActivePresenceGauge() {
} while (cursor !== "0");
// Clear previous data
activePresenceGauge.clear();
activePresenceGauge.clear({ except: [...serviceCounts.keys()] });
// Set new data
for (const [serviceVersion, count] of serviceCounts.entries()) {

View File

@@ -6,7 +6,7 @@ import createRedis from "./functions/createRedis.js";
import { setSessionCounter } from "./functions/setSessionCounter.js";
import "./tracing.js";
import { updateActivePresenceGauge } from "./functions/updateActivePresenceGauge.js";
import { reloadIpLocationApi } from "./functions/lookupIp.js";
// import { reloadIpLocationApi } from "./functions/lookupIp.js";
import { cleanupOldUserData } from "./functions/cleanupOldUserData.js";
export const redis = createRedis();
@@ -45,18 +45,18 @@ void new CronJob(
true,
);
void new CronJob(
// Every day at 9am
"0 9 * * *",
() => {
reloadIpLocationApi();
},
undefined,
true,
undefined,
undefined,
true,
);
// void new CronJob(
// // Every day at 9am
// "0 9 * * *",
// () => {
// reloadIpLocationApi();
// },
// undefined,
// true,
// undefined,
// undefined,
// true,
// );
void new CronJob(
// Every day at 1am