fix ProjectionSnapshotRepositoryInMemory.excludeTheHeadBySize

This commit is contained in:
2025-04-05 05:10:27 +02:00
parent d05bf62bf0
commit 0bfeef8a91
2 changed files with 4 additions and 12 deletions

View File

@@ -144,14 +144,8 @@ class ProjectionSnapshotRepositoryInMemory<E : Event<ID>, P : Projection<ID>, ID
*/
private fun FilteredList<P>.excludeTheHeadBySize(): FilteredList<P> {
// filter if size exceeds the limit
if (size > snapshotCacheConfig.maxSnapshotCacheSize) {
val numberToRemove = size - snapshotCacheConfig.maxSnapshotCacheSize
if (numberToRemove > 0) {
return sortedBy { it.first.lastEventVersion }
.takeLast(numberToRemove)
}
}
return this
return sortedBy { it.first.lastEventVersion }
.dropLast(snapshotCacheConfig.maxSnapshotCacheSize)
}
/**