dashjay commented on code in PR #3346:
URL: https://github.com/apache/kvrocks/pull/3346#discussion_r2730137906


##########
src/types/redis_hash.cc:
##########
@@ -40,12 +46,12 @@ rocksdb::Status Hash::GetMetadata(engine::Context &ctx, 
const Slice &ns_key, Has
 
 rocksdb::Status Hash::Size(engine::Context &ctx, const Slice &user_key, 
uint64_t *size) {
   *size = 0;
-
-  std::string ns_key = AppendNamespacePrefix(user_key);
-  HashMetadata metadata(false);
-  rocksdb::Status s = GetMetadata(ctx, ns_key, &metadata);
-  if (!s.ok()) return s;
-  *size = metadata.size;
+  std::vector<FieldValue> fields;
+  auto s = this->GetAll(ctx, user_key, &fields, HashFetchType::kOnlyKey);
+  if (!s.ok()) {
+    return s;
+  }
+  *size = fields.size();

Review Comment:
   O(N) problem



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to