mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Filter improvements
This commit is contained in:
@@ -1501,7 +1501,10 @@ public final class SqliteValueBox: ValueBox {
|
||||
public func filteredRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey, values: (ValueBoxKey, ReadBuffer) -> ValueBoxFilterResult, limit: Int) {
|
||||
var currentStart = start
|
||||
var acceptedCount = 0
|
||||
while acceptedCount < limit {
|
||||
while true {
|
||||
if limit > 0 && acceptedCount >= limit {
|
||||
break
|
||||
}
|
||||
var hadStop = false
|
||||
var lastKey: ValueBoxKey?
|
||||
self.range(table, start: currentStart, end: end, values: { key, value in
|
||||
@@ -1530,6 +1533,41 @@ public final class SqliteValueBox: ValueBox {
|
||||
}
|
||||
}
|
||||
|
||||
public func filteredRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey, keys: (ValueBoxKey) -> ValueBoxFilterResult, limit: Int) {
|
||||
var currentStart = start
|
||||
var acceptedCount = 0
|
||||
while true {
|
||||
if limit > 0 && acceptedCount >= limit {
|
||||
break
|
||||
}
|
||||
var hadStop = false
|
||||
var lastKey: ValueBoxKey?
|
||||
self.range(table, start: currentStart, end: end, keys: { key in
|
||||
lastKey = key
|
||||
let result = keys(key)
|
||||
switch result {
|
||||
case .accept:
|
||||
acceptedCount += 1
|
||||
return true
|
||||
case .skip:
|
||||
return true
|
||||
case .stop:
|
||||
hadStop = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, limit: limit)
|
||||
if let lastKey = lastKey {
|
||||
currentStart = lastKey
|
||||
} else {
|
||||
break
|
||||
}
|
||||
if hadStop {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func range(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey, keys: (ValueBoxKey) -> Bool, limit: Int) {
|
||||
precondition(self.queue.isCurrent())
|
||||
if let _ = self.tables[table.id] {
|
||||
|
||||
Reference in New Issue
Block a user