fix(channels): pending message compaction never triggering

Move count assignment before RAM trim in Record() so MaybeCompact
receives pre-trim count (51) that exceeds threshold (50), allowing
compaction to fire. Previously count was always ≤ limit after trim.
This commit is contained in:
viettranx committed 2026-03-10 00:16:29 +07:00
1 parent bdb60de7ae
commit 30080f1acf
1 file changed
+1 -1
+1 -1
View File
@@ -120,11 +120,11 @@ func (ph *PendingHistory) Record(historyKey string, entry HistoryEntry, limit in
ph.mu.Lock()
existing := ph.entries[historyKey]
existing = append(existing, entry)
count = len(existing) // capture pre-trim count so MaybeCompact sees threshold exceeded
if len(existing) > limit {
existing = existing[len(existing)-limit:]
}
ph.entries[historyKey] = existing
count = len(existing)
ph.removeFromOrder(historyKey)
ph.order = append(ph.order, historyKey)
ph.evictOldKeys()