This commit is contained in:
jhartworks
2026-06-25 14:35:57 +02:00
parent bf1214239f
commit a12ef41d1b
116 changed files with 978 additions and 59769 deletions
+37 -8
View File
@@ -1,4 +1,7 @@
const META_PREFIX = "meta:isp:";
export const LEGACY_POINT_LIMIT = 200;
export const LOCAL_POINT_LIMIT = 2000;
export function buildPointKey(isp, pointIndex) {
return `${isp}:${pointIndex}`;
@@ -17,8 +20,8 @@ export function sanitizeIspName(value) {
export function sanitizePointIndex(value) {
const pointIndex = Number(value);
if (!Number.isInteger(pointIndex) || pointIndex < 1 || pointIndex > 200) {
throw new Error("Point index must be between 1 and 200.");
if (!Number.isInteger(pointIndex) || pointIndex < 1 || pointIndex > LOCAL_POINT_LIMIT) {
throw new Error(`Point index must be between 1 and ${LOCAL_POINT_LIMIT}.`);
}
return pointIndex;
@@ -48,7 +51,7 @@ export function parseTrendValue(rawValue, factor = 1) {
function buildValueColumns() {
const columns = [];
for (let index = 1; index <= 200; index += 1) {
for (let index = 1; index <= LOCAL_POINT_LIMIT; index += 1) {
columns.push('`Wert' + index + '` TEXT NULL');
}
@@ -136,6 +139,31 @@ function createDefaultPoint(index) {
};
}
async function ensureWideTrendColumns(pool, tableName) {
const [columns] = await pool.query(
`
SELECT COLUMN_NAME AS columnName
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = ?
AND COLUMN_NAME LIKE 'Wert%'
`,
[tableName]
);
const existing = new Set(columns.map((column) => column.columnName));
const missing = [];
for (let index = 1; index <= LOCAL_POINT_LIMIT; index += 1) {
const columnName = `Wert${index}`;
if (!existing.has(columnName)) {
missing.push(`ADD COLUMN \`${columnName}\` TEXT NULL`);
}
}
for (let index = 0; index < missing.length; index += 50) {
await pool.query(`ALTER TABLE \`${tableName}\` ${missing.slice(index, index + 50).join(", ")}`);
}
}
export async function createWideTrendTable(pool, tableName) {
const safeTable = sanitizeIspName(tableName);
const sql = `
@@ -149,6 +177,7 @@ export async function createWideTrendTable(pool, tableName) {
`;
await pool.query(sql);
await ensureWideTrendColumns(pool, safeTable);
return safeTable;
}
@@ -197,7 +226,7 @@ export async function getAvailableIsps(pool, dbName) {
});
}
export function createDefaultMetadata(isp, pointCount = 200) {
export function createDefaultMetadata(isp, pointCount = LEGACY_POINT_LIMIT) {
const points = {};
for (let index = 1; index <= pointCount; index += 1) {
@@ -212,7 +241,7 @@ export function createDefaultMetadata(isp, pointCount = 200) {
};
}
export async function ensureIspMetadata(redis, isp, pointCount = 200) {
export async function ensureIspMetadata(redis, isp, pointCount = LEGACY_POINT_LIMIT) {
const safeIsp = sanitizeIspName(isp);
const key = `${META_PREFIX}${safeIsp}`;
const existing = await redis.get(key);
@@ -285,8 +314,8 @@ export async function ensureIspMetadata(redis, isp, pointCount = 200) {
return metadata;
}
export async function updateIspMetadata(redis, isp, updater) {
const metadata = await ensureIspMetadata(redis, isp);
export async function updateIspMetadata(redis, isp, updater, pointCount = LEGACY_POINT_LIMIT) {
const metadata = await ensureIspMetadata(redis, isp, pointCount);
const updated = updater(JSON.parse(JSON.stringify(metadata)));
await redis.set(`${META_PREFIX}${sanitizeIspName(isp)}`, JSON.stringify(updated));
return updated;
@@ -309,7 +338,7 @@ export async function getPointDescriptors(redis, points) {
const descriptors = [];
for (const [isp, pointIndexes] of grouped.entries()) {
const metadata = await ensureIspMetadata(redis, isp);
const metadata = await ensureIspMetadata(redis, isp, LOCAL_POINT_LIMIT);
pointIndexes.forEach((pointIndex) => {
const pointMeta = metadata.points[String(pointIndex)];