mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-08-22 07:16:03 +00:00
Clean expired IDs before marked-entry trimming
This commit is contained in:
parent
b896dd3f61
commit
fb5b134936
@ -57,8 +57,10 @@ final class MessageDeduplicator {
|
||||
lock.lock()
|
||||
defer { lock.unlock() }
|
||||
|
||||
let now = Date()
|
||||
cleanupOldEntries(before: now.addingTimeInterval(-maxAge))
|
||||
|
||||
if lookup[id] == nil {
|
||||
let now = Date()
|
||||
entries.append(Entry(id: id, timestamp: now))
|
||||
lookup[id] = now
|
||||
trimIfNeeded()
|
||||
|
||||
@ -25,4 +25,20 @@ struct MessageDeduplicatorTests {
|
||||
#expect(deduplicator.contains("d"))
|
||||
#expect(deduplicator.contains("e"))
|
||||
}
|
||||
|
||||
@Test func markProcessed_cleansExpiredEntriesBeforeCountTrim() async {
|
||||
let deduplicator = MessageDeduplicator(maxAge: 0.1, maxCount: 4)
|
||||
|
||||
deduplicator.markProcessed("expired")
|
||||
try? await Task.sleep(nanoseconds: 200_000_000)
|
||||
|
||||
for id in ["b", "c", "d", "e"] {
|
||||
deduplicator.markProcessed(id)
|
||||
}
|
||||
|
||||
#expect(deduplicator.contains("b"))
|
||||
#expect(deduplicator.contains("c"))
|
||||
#expect(deduplicator.contains("d"))
|
||||
#expect(deduplicator.contains("e"))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user