fix: delete stale trend_evidence before inserting to prevent duplicate accumulation
This commit is contained in:
@@ -841,7 +841,11 @@ async def persist_trend_evidence(
|
|||||||
supporting: list[RankedEvidence],
|
supporting: list[RankedEvidence],
|
||||||
opposing: list[RankedEvidence],
|
opposing: list[RankedEvidence],
|
||||||
) -> int:
|
) -> int:
|
||||||
"""Insert evidence mapping rows for a trend window. Returns count inserted."""
|
"""Insert evidence mapping rows for a trend window. Returns count inserted.
|
||||||
|
|
||||||
|
Deletes any existing evidence for this trend window first to prevent
|
||||||
|
duplicate accumulation across aggregation cycles.
|
||||||
|
"""
|
||||||
rows: list[tuple[str, str, str, float, float, float, float, float, float]] = []
|
rows: list[tuple[str, str, str, float, float, float, float, float, float]] = []
|
||||||
for ev in supporting:
|
for ev in supporting:
|
||||||
# Skip non-UUID document IDs (e.g. pattern signal synthetic IDs)
|
# Skip non-UUID document IDs (e.g. pattern signal synthetic IDs)
|
||||||
@@ -861,6 +865,12 @@ async def persist_trend_evidence(
|
|||||||
ev.recency_component, ev.confidence_component, ev.sentiment_value,
|
ev.recency_component, ev.confidence_component, ev.sentiment_value,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
# Clear stale evidence before inserting fresh rows
|
||||||
|
await pool.execute(
|
||||||
|
"DELETE FROM trend_evidence WHERE trend_window_id = $1",
|
||||||
|
trend_window_id,
|
||||||
|
)
|
||||||
|
|
||||||
if not rows:
|
if not rows:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user