aboutsummaryrefslogtreecommitdiffhomepage
path: root/tddb
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2024-01-05 15:11:49 +0300
committerlevlam <levlam@telegram.org>2024-01-05 15:11:49 +0300
commit9e0bb80dcf5bb154fe6c5268c796a227e5a7c311 (patch)
tree6040f53ae573fa43f6c15aef691e1c19b41d0caf /tddb
parentf4bafbdc86e5d24972732c91b9676030c78a8f44 (diff)
Don't return common key prefix in SqliteKeyValue::get_by_prefix.
Diffstat (limited to 'tddb')
-rw-r--r--tddb/td/db/SqliteKeyValue.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/tddb/td/db/SqliteKeyValue.h b/tddb/td/db/SqliteKeyValue.h
index e7d316e0b..222cbeb12 100644
--- a/tddb/td/db/SqliteKeyValue.h
+++ b/tddb/td/db/SqliteKeyValue.h
@@ -79,11 +79,17 @@ class SqliteKeyValue {
if (!prefix.empty()) {
next = next_prefix(prefix);
}
- get_by_range(prefix, next, callback);
+ get_by_range_impl(prefix, next, true, callback);
}
template <class CallbackT>
void get_by_range(Slice from, Slice till, CallbackT &&callback) {
+ get_by_range_impl(from, till, false, std::move(callback));
+ }
+
+ private:
+ template <class CallbackT>
+ void get_by_range_impl(Slice from, Slice till, bool strip_key_prefix, CallbackT &&callback) {
SqliteStatement *stmt = nullptr;
if (from.empty()) {
stmt = &get_all_stmt_;
@@ -100,14 +106,17 @@ class SqliteKeyValue {
auto guard = stmt->guard();
stmt->step().ensure();
while (stmt->has_row()) {
- if (!callback(stmt->view_blob(0), stmt->view_blob(1))) {
+ auto key = stmt->view_blob(0);
+ if (strip_key_prefix) {
+ key.remove_prefix(from.size());
+ }
+ if (!callback(key, stmt->view_blob(1))) {
return;
}
stmt->step().ensure();
}
}
- private:
string table_name_;
SqliteDb db_;
SqliteStatement get_stmt_;