ahuang98 commented on code in PR #19079:
URL: https://github.com/apache/kafka/pull/19079#discussion_r1982266631


##########
metadata/src/main/java/org/apache/kafka/image/ClientQuotasImage.java:
##########
@@ -126,40 +144,45 @@ public DescribeClientQuotasResponseData 
describe(DescribeClientQuotasRequestData
                     "user or clientId filter component.");
             }
         }
-        // TODO: this is O(N). We should add indexing here to speed it up. See 
KAFKA-13022.
-        for (Entry<ClientQuotaEntity, ClientQuotaImage> entry : 
entities.entrySet()) {
-            ClientQuotaEntity entity = entry.getKey();
-            ClientQuotaImage quotaImage = entry.getValue();
-            if (matches(entity, exactMatch, typeMatch, request.strict())) {
-                response.entries().add(toDescribeEntry(entity, quotaImage));
-            }
-        }
-        return response;
-    }
 
-    private static boolean matches(ClientQuotaEntity entity,
-                                   Map<String, String> exactMatch,
-                                   Set<String> typeMatch,
-                                   boolean strict) {
-        if (strict) {
-            if (entity.entries().size() != exactMatch.size() + 
typeMatch.size()) {
-                return false;
+        Set<ClientQuotaEntity> addedEntities = new HashSet<>();
+        for (Entry<String, String> exactMatchEntry : exactMatch.entrySet()) {
+            if (entitiesByType.containsKey(exactMatchEntry.getKey()) &&
+                
entitiesByType.get(exactMatchEntry.getKey()).containsKey(exactMatchEntry.getValue()))
 {
+                for (Entry<ClientQuotaEntity, ClientQuotaImage> entry : 
entitiesByType.get(exactMatchEntry.getKey()).get(exactMatchEntry.getValue())) {
+                    if (request.strict() && 
!entry.getKey().entries().equals(exactMatch)) {

Review Comment:
   does this have to equal exactMatch as long as entry.getKey().entries() are 
encompassed by both typeMatch and exactMatch?



##########
metadata/src/main/java/org/apache/kafka/image/ClientQuotasImage.java:
##########
@@ -126,40 +144,45 @@ public DescribeClientQuotasResponseData 
describe(DescribeClientQuotasRequestData
                     "user or clientId filter component.");
             }
         }
-        // TODO: this is O(N). We should add indexing here to speed it up. See 
KAFKA-13022.
-        for (Entry<ClientQuotaEntity, ClientQuotaImage> entry : 
entities.entrySet()) {
-            ClientQuotaEntity entity = entry.getKey();
-            ClientQuotaImage quotaImage = entry.getValue();
-            if (matches(entity, exactMatch, typeMatch, request.strict())) {
-                response.entries().add(toDescribeEntry(entity, quotaImage));
-            }
-        }
-        return response;
-    }
 
-    private static boolean matches(ClientQuotaEntity entity,
-                                   Map<String, String> exactMatch,
-                                   Set<String> typeMatch,
-                                   boolean strict) {
-        if (strict) {
-            if (entity.entries().size() != exactMatch.size() + 
typeMatch.size()) {
-                return false;
+        Set<ClientQuotaEntity> addedEntities = new HashSet<>();
+        for (Entry<String, String> exactMatchEntry : exactMatch.entrySet()) {
+            if (entitiesByType.containsKey(exactMatchEntry.getKey()) &&
+                
entitiesByType.get(exactMatchEntry.getKey()).containsKey(exactMatchEntry.getValue()))
 {
+                for (Entry<ClientQuotaEntity, ClientQuotaImage> entry : 
entitiesByType.get(exactMatchEntry.getKey()).get(exactMatchEntry.getValue())) {

Review Comment:
   nit: local vars to reduce redundant gets and improve readability?



-- 
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