mirror of
https://github.com/johndoe6345789/goodpackagerepo.git
synced 2026-04-24 13:54:59 +00:00
Fix remaining code review issues
- Prevent double-counting in cas_put by adding internal flag to put() - Pass limit parameter directly to keys() method in /rocksdb/keys endpoint - Restore __del__ method to ensure proper RocksDB cleanup on garbage collection Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user