jerryshao commented on code in PR #6752:
URL: https://github.com/apache/gravitino/pull/6752#discussion_r2019473319


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java:
##########
@@ -230,20 +245,32 @@ public List<MetadataObject> 
listAssociatedMetadataObjectsForTag(NameIdentifier t
                   
mapper.listTagMetadataObjectRelsByMetalakeAndTagName(metalakeName, tagName));
 
       List<MetadataObject> metadataObjects = Lists.newArrayList();
-      for (TagMetadataObjectRelPO po : tagMetadataObjectRelPOs) {
-        String fullName =
-            MetadataObjectService.getMetadataObjectFullName(
-                po.getMetadataObjectType(), po.getMetadataObjectId());
-
-        // Metadata object may be deleted asynchronously when we query the 
name, so it will return
-        // null. We should skip this metadata object.
-        if (fullName == null) {
-          continue;
-        }
-
-        MetadataObject.Type type = 
MetadataObject.Type.valueOf(po.getMetadataObjectType());
-        metadataObjects.add(MetadataObjects.parse(fullName, type));
-      }
+      tagMetadataObjectRelPOs.stream()
+          .collect(
+              Collectors.groupingBy(t -> 
MetadataObject.Type.valueOf(t.getMetadataObjectType())))
+          .forEach(
+              (type, rels) -> {
+                List<Long> metadataObjectIds =
+                    rels.stream()
+                        .map(TagMetadataObjectRelPO::getMetadataObjectId)
+                        .collect(Collectors.toList());
+                Map<Long, String> metadataObjectNames =
+                    Optional.of(TYPE_FUNCTION_MAP.get(type))
+                        .map(f -> f.apply(metadataObjectIds))
+                        .orElseThrow(
+                            () ->
+                                new IllegalArgumentException(
+                                    "Unexpected to reach here for metadata 
object type: " + type));
+
+                metadataObjectNames.forEach(
+                    (id, fullName) -> {
+                      // Metadata object may be deleted asynchronously when we 
query the name, so it
+                      // will return null, we should skip this metadata object.
+                      if (fullName != null) {
+                        metadataObjects.add(MetadataObjects.parse(fullName, 
type));
+                      }
+                    });
+              });

Review Comment:
   Do we have a test to cover this, if not please add a test.



-- 
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: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to