diff --git a/backend/app.py b/backend/app.py index 0399256..eb37999 100644 --- a/backend/app.py +++ b/backend/app.py @@ -687,14 +687,11 @@ def rocksdb_keys(): prefix = request.args.get("prefix", None) limit = int(request.args.get("limit", "100")) - keys = kv_store.keys(prefix) + # Pass limit to keys() method for efficiency + keys = kv_store.keys(prefix, limit=limit) - # Limit results - if len(keys) > limit: - keys = keys[:limit] - truncated = True - else: - truncated = False + # Check if we hit the limit (might have more keys) + truncated = len(keys) == limit return jsonify({ "ok": True, diff --git a/backend/rocksdb_store.py b/backend/rocksdb_store.py index 26db1b8..5fd4a38 100644 --- a/backend/rocksdb_store.py +++ b/backend/rocksdb_store.py @@ -71,14 +71,16 @@ class RocksDBStore: self.stats['cache_misses'] += 1 return None - def put(self, key: str, value: Any) -> None: + def put(self, key: str, value: Any, _internal: bool = False) -> None: """Store value in RocksDB. Args: key: Key to store value: Value to store (will be JSON serialized) + _internal: If True, don't increment operation counter (internal use) """ - self.stats['operations']['put'] += 1 + if not _internal: + self.stats['operations']['put'] += 1 # Serialize value as JSON value_json = json.dumps(value) @@ -106,7 +108,8 @@ class RocksDBStore: except Exception: pass - self.put(key, value) + # Use internal put to avoid double-counting + self.put(key, value, _internal=True) return True def delete(self, key: str) -> None: @@ -210,5 +213,4 @@ class RocksDBStore: def __del__(self): """Cleanup on deletion.""" - # Note: __del__ is not guaranteed to be called - pass + self.close()