Skip to content

Commit ec8c016

Browse files
committed
refactor(kv): probe the entry once per rewrite
The presence check and the old-expiry read now share a single entry metadata lookup.
1 parent cde126f commit ec8c016

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

‎nodedb/src/engine/kv/engine_write.rs‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,14 @@ impl KvEngine {
179179
} = params;
180180

181181
let tkey = table_key(database_id, tenant_id, collection);
182-
let present = self
183-
.tables
184-
.get(&tkey)
185-
.is_some_and(|t| t.get_entry_meta(key).is_some());
186-
if matches!(identity, RowIdentity::KeepExisting) && !present {
182+
// One probe serves both the rewrite's presence check and the old expiry.
183+
let old_meta = self.tables.get(&tkey).and_then(|t| t.get_entry_meta(key));
184+
if matches!(identity, RowIdentity::KeepExisting) && old_meta.is_none() {
187185
return None;
188186
}
189187

190-
// Single-pass: check indexes + get old entry meta in one HashMap lookup.
191188
let has_indexes = self.indexes.get(&tkey).is_some_and(|idx| !idx.is_empty());
192-
let old_expire = self
193-
.tables
194-
.get(&tkey)
195-
.and_then(|t| t.get_entry_meta(key))
196-
.and_then(|m| {
197-
if m.has_ttl {
198-
Some(m.expire_at_ms)
199-
} else {
200-
None
201-
}
202-
});
189+
let old_expire = old_meta.and_then(|m| m.has_ttl.then_some(m.expire_at_ms));
203190

204191
// Cancel old expiry (before mutating the table).
205192
if let Some(old_ms) = old_expire {

0 commit comments

Comments
 (0)