cleanup(memory): impact läser bara egen userPreferences-rad

This commit is contained in:
Sven (AAMOS AI)
2026-08-11 07:28:25 +07:00
parent 989c242d2c
commit 4a63c5cb67
+20 -5
View File
@@ -132,15 +132,30 @@ export async function computeMemoryImpact(options: MemoryImpactOptions): Promise
.where(eq(schema.householdMembers.householdId, householdId)) .where(eq(schema.householdMembers.householdId, householdId))
: []; : [];
const memberIds = members.length ? members.map((m) => m.userId) : [userId]; const memberIds = members.length ? members.map((m) => m.userId) : [userId];
const allPrefs = await db
// Läs bara den anropande användarens fulla preferensrad; personliga data från
// andra hushållsmedlemmar läcker aldrig in i impact-beräkningen.
const myPrefs = await db
.select() .select()
.from(schema.userPreferences) .from(schema.userPreferences)
.where(eq(schema.userPreferences.userId, userId))
.limit(1)
.then((rows) => rows[0]);
// För säkerhetsfiltrering behöver vi endast de begränsande fälten från alla
// medlemmar — inte deras personliga preferenser.
const householdRestrictionRows = await db
.select({
allergens: schema.userPreferences.allergens,
avoidIngredientIds: schema.userPreferences.avoidIngredientIds,
spiceLevelMax: schema.userPreferences.spiceLevelMax,
})
.from(schema.userPreferences)
.where(inArray(schema.userPreferences.userId, memberIds)); .where(inArray(schema.userPreferences.userId, memberIds));
const combinedAllergens = [...new Set(allPrefs.flatMap((p) => p.allergens))]; const combinedAllergens = [...new Set(householdRestrictionRows.flatMap((p) => p.allergens))];
const combinedAvoid = [...new Set(allPrefs.flatMap((p) => p.avoidIngredientIds))]; const combinedAvoid = [...new Set(householdRestrictionRows.flatMap((p) => p.avoidIngredientIds))];
const strictestSpice = Math.min(...allPrefs.map((p) => p.spiceLevelMax), 5); const strictestSpice = Math.min(...householdRestrictionRows.map((p) => p.spiceLevelMax), 5);
const myPrefs = allPrefs.find((p) => p.userId === userId);
// --- 3. Kandidater --- // --- 3. Kandidater ---
const candidates = await db const candidates = await db