Copilot commented on code in PR #7086:
URL: https://github.com/apache/shenyu/pull/7086#discussion_r4032820441


##########
shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java:
##########
@@ -125,6 +125,7 @@ public MetaData obtain(final String path) {
                     final MetaData value = META_DATA_MAP.values()
                             .stream()
                             .filter(data -> data.getEnabled() && 
PathMatchUtils.match(data.getPath(), path))
+                            .sorted((left, right) -> 
PathMatchUtils.compare(left.getPath(), right.getPath(), path))

Review Comment:
   This ordering only runs on a cache miss. If `/api/**` has already cached 
`/api/users/42`, subsequently registering or enabling `/api/users/**` calls 
`clean("/api/users/**")`, but that concrete path is mapped under `/api/**`; the 
stale broad metadata therefore continues to be returned indefinitely. 
Invalidate cached concrete paths matched by a newly added/updated wildcard (or 
clear the lookup cache) so dynamic metadata updates also apply specificity 
ordering, and cover that update sequence in the regression test.



##########
shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java:
##########
@@ -125,6 +125,7 @@ public MetaData obtain(final String path) {
                     final MetaData value = META_DATA_MAP.values()
                             .stream()
                             .filter(data -> data.getEnabled() && 
PathMatchUtils.match(data.getPath(), path))
+                            .sorted((left, right) -> 
PathMatchUtils.compare(left.getPath(), right.getPath(), path))
                             .findFirst()

Review Comment:
   Sorting every matching metadata entry makes each uncached path lookup O(n 
log n), even though only the best candidate is needed. This runs in gateway 
request handling; use `min` with the same comparator to retain specificity 
selection with an O(n) scan.



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