Fas 2 steg 2: Inventory Trust Engine - decay-profiler och cache-jobb
This commit is contained in:
@@ -2,6 +2,7 @@ import { createHash, randomBytes, randomUUID } from "node:crypto";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import type { Database } from "@app/database";
|
||||
import { schema } from "@app/database";
|
||||
import type { DecayProfile } from "@app/inventory-engine";
|
||||
import type { EventType } from "@app/shared-types";
|
||||
import type { NewDomainEvent } from "@app/events";
|
||||
import { errors } from "./errors.js";
|
||||
@@ -145,3 +146,18 @@ export async function audit(
|
||||
export function newCorrelationId(): string {
|
||||
return randomUUID();
|
||||
}
|
||||
|
||||
/** Hämta den aktiva trust-decay-profilen. Cachas i praktiken av databasen;
|
||||
* funktionen returnerar alltid en giltig profil (default fallback). */
|
||||
export async function getActiveDecayProfile(db: Database): Promise<DecayProfile> {
|
||||
const [profile] = await db
|
||||
.select({ halfLifeDays: schema.inventoryDecayProfiles.halfLifeDays, staleAfterDays: schema.inventoryDecayProfiles.staleAfterDays })
|
||||
.from(schema.inventoryDecayProfiles)
|
||||
.where(eq(schema.inventoryDecayProfiles.active, true))
|
||||
.orderBy(schema.inventoryDecayProfiles.createdAt)
|
||||
.limit(1);
|
||||
return {
|
||||
halfLifeDays: profile?.halfLifeDays ?? 7,
|
||||
staleAfterDays: profile?.staleAfterDays ?? 30,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user