Skip to content

Commit dd33fc2

Browse files
Avoid extra allocations in RestGetAliasesAction
When no explicit aliases are provided in the call there is no need to collect the index names or aliases into HashSets if they won't be used. Also fixed where the index name was being added for each loop of the alias list.
1 parent b563145 commit dd33fc2

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,25 @@ static RestResponse buildRestResponse(
8484
) throws Exception {
8585
final Set<String> indicesToDisplay = new HashSet<>();
8686
final Set<String> returnedAliasNames = new HashSet<>();
87-
for (final Map.Entry<String, List<AliasMetadata>> cursor : responseAliasMap.entrySet()) {
88-
for (final AliasMetadata aliasMetadata : cursor.getValue()) {
87+
if (aliasesExplicitlyRequested || requestedAliases.length > 0) {
88+
for (final Map.Entry<String, List<AliasMetadata>> cursor : responseAliasMap.entrySet()) {
8989
if (aliasesExplicitlyRequested) {
9090
// only display indices that have aliases
9191
indicesToDisplay.add(cursor.getKey());
9292
}
93-
returnedAliasNames.add(aliasMetadata.alias());
93+
if (requestedAliases.length > 0) {
94+
for (final AliasMetadata aliasMetadata : cursor.getValue()) {
95+
returnedAliasNames.add(aliasMetadata.alias());
96+
}
97+
}
9498
}
9599
}
96-
dataStreamAliases.entrySet()
97-
.stream()
98-
.flatMap(entry -> entry.getValue().stream())
99-
.forEach(dataStreamAlias -> returnedAliasNames.add(dataStreamAlias.getName()));
100+
if (requestedAliases.length > 0) {
101+
dataStreamAliases.entrySet()
102+
.stream()
103+
.flatMap(entry -> entry.getValue().stream())
104+
.forEach(dataStreamAlias -> returnedAliasNames.add(dataStreamAlias.getName()));
105+
}
100106

101107
// compute explicitly requested aliases that have are not returned in the result
102108
final SortedSet<String> missingAliases = new TreeSet<>();

0 commit comments

Comments
 (0)