diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java index 50586f3a3..1db652e2f 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java @@ -14,7 +14,6 @@ package google.registry.ui.server.console; -import static com.google.common.collect.ImmutableList.toImmutableList; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.request.Action.Method.GET; import static org.joda.time.DateTimeZone.UTC; @@ -34,7 +33,6 @@ import google.registry.util.Clock; import jakarta.inject.Inject; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.List; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; import org.joda.time.DateTime; @@ -106,21 +104,27 @@ public class ConsoleDumDownloadAction extends ConsoleApiAction { private void writeCsv(CSVPrinter printer) throws IOException { String sql = SQL_TEMPLATE.replaceAll(":now", clock.nowUtc().toString()); - // We deliberately don't want to use ImmutableList.copyOf because underlying list may contain - // large amount of records and that will degrade performance. - List queryResult = - tm().transact( - () -> - tm().getEntityManager() - .createNativeQuery(sql) - .setParameter("registrarId", registrarId) - .setHint("org.hibernate.fetchSize", 1000) - .getResultList()); - - ImmutableList formattedRecords = - queryResult.stream().map(r -> r.split(",")).collect(toImmutableList()); printer.printRecord( ImmutableList.of("Domain Name", "Creation Time", "Expiration Time", "Domain Statuses")); - printer.printRecords(formattedRecords); + + tm().transact( + () -> { + try (var resultStream = + tm().getEntityManager() + .createNativeQuery(sql, String.class) + .setParameter("registrarId", registrarId) + .setHint("org.hibernate.fetchSize", 1000) + .getResultStream()) { + + resultStream.forEach( + row -> { + try { + printer.printRecord((Object[]) ((String) row).split(",")); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + }); } }