Skip to content

Apache Lucene open-source search software

Fix TestLRUCache after changes to the implementation (#15965)

Dawid Weiss335cce89bfaf
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f714ce67643..56e68616a12 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -120,7 +120,7 @@ Improvements
* GITHUB#15225: Improve package documentation for org.apache.lucene.util. (Syed Mohammad Saad)
-* GTIHUB#15558: Refactor QueryCache for performance. (Sagar Upadhyaya)
+* GITHUB#15558: Refactor QueryCache for performance. (Sagar Upadhyaya)
Optimizations
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java b/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
index 8cf9207730a..0344ccadcdf 100644
--- a/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
+++ b/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
@@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -523,14 +524,17 @@ public class LRUQueryCache implements QueryCache, Accountable, Closeable {
}
}
- // pkg-private for testing
- // return the list of cached queries in LRU order
+ // package-private for testing only; returns the list of unique
+ // cached queries in LRU order.
List<Query> cachedQueries() {
+ Set<Query> dedup = new HashSet<>();
List<Query> list = new ArrayList<>();
for (int i = 0; i < this.numberOfPartitions; i++) {
List<QueryCacheKey> segmentQueryList = lruQueryCachePartition[i].cachedQueries();
for (QueryCacheKey queryCacheKey : segmentQueryList) {
- list.add(queryCacheKey.query);
+ if (dedup.add(queryCacheKey.query)) {
+ list.add(queryCacheKey.query);
+ }
}
}
return list;