Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reusing empty NamedList rather than recreating a new empty NamedList … #2932

Merged
merged 7 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions solr/core/src/java/org/apache/solr/request/SimpleFacets.java
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,12 @@ public void execute(Runnable r) {
* @see #getFieldMissingCount
* @see #getFacetTermEnumCounts
*/
public NamedList<Object> getFacetFieldCounts() throws IOException, SyntaxError {
public SimpleOrderedMap<Object> getFacetFieldCounts() throws IOException, SyntaxError {

NamedList<Object> res = new SimpleOrderedMap<>();
String[] facetFs = global.getParams(FacetParams.FACET_FIELD);

if (null == facetFs) {
return res;
return SimpleOrderedMap.of();
}

// Passing a negative number for FACET_THREADS implies an unlimited number of threads is
Expand All @@ -891,6 +891,7 @@ public NamedList<Object> getFacetFieldCounts() throws IOException, SyntaxError {
fdebugParent.putInfoItem("maxThreads", maxThreads);
}

SimpleOrderedMap<Object> res;
try {
// Loop over fields; submit to executor, keeping the future
for (String f : facetFs) {
Expand All @@ -914,10 +915,8 @@ public NamedList<Object> getFacetFieldCounts() throws IOException, SyntaxError {
result.add(key, getTermCounts(facetValue, parsed));
}
return result;
} catch (SolrException se) {
} catch (SolrException | ExitableDirectoryReader.ExitingReaderException se) {
throw se;
} catch (ExitableDirectoryReader.ExitingReaderException timeout) {
throw timeout;
} catch (Exception e) {
throw new SolrException(
ErrorCode.SERVER_ERROR, "Exception during facet.field: " + facetValue, e);
Expand All @@ -932,6 +931,7 @@ public NamedList<Object> getFacetFieldCounts() throws IOException, SyntaxError {
futures.add(runnableFuture);
} // facetFs loop

res = new SimpleOrderedMap<>();
// Loop over futures to get the values. The order is the same as facetFs but shouldn't matter.
for (Future<NamedList<?>> future : futures) {
res.addAll(future.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* serialized. It aims to minimize overhead and to be efficient at adding new elements.
*/
public class SimpleOrderedMap<T> extends NamedList<T> {

private static final SimpleOrderedMap<Object> EMPTY = new SimpleOrderedMap<>(List.of());
/** Creates an empty instance */
public SimpleOrderedMap() {
super();
Expand Down Expand Up @@ -67,4 +69,23 @@ public SimpleOrderedMap<T> clone() {
newList.addAll(nvPairs);
return new SimpleOrderedMap<>(newList);
}

/**
* Returns a shared, empty, and immutable instance of SimpleOrderedMap.
* @return Empty SimpleOrderedMap (immutable)
*/
public static SimpleOrderedMap<Object> of() {
return EMPTY;
}

/**
* Returns an immutable instance of SimpleOrderedMap with a single key-value pair.
* @return SimpleOrderedMap containing one key-value pair
*/

public static <T> SimpleOrderedMap<T> of(String name, T val)
{
return new SimpleOrderedMap<>(List.of(name, val));
}

}
Loading