Skip to content

Optimize console domain list fetch performance#3110

Closed
CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:fix-domain-list-console
Closed

Optimize console domain list fetch performance#3110
CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:fix-domain-list-console

Conversation

@CydeWeys

@CydeWeys CydeWeys commented Jun 26, 2026

Copy link
Copy Markdown
Member

Optimize the domain list fetch action in the registrar console by implementing a lightweight DTO projection and eager fetch join to eliminate N+1 queries.

Previously, ConsoleDomainListAction returned a paginated list of full Domain JPA entities. During Gson serialization, accessing lazy-loaded element collections (specifically 'statuses' and 'nsHosts') triggered a massive N+1 query loop, executing hundreds of secondary SQL queries per request and causing the endpoint to take dozens of seconds (and sometimes fail with timeouts) on environments with large datasets like alpha.

This commit resolves the performance bottleneck by:

  1. Introducing a lightweight 'ConsoleDomainInfo' DTO to expose only the five fields the frontend actually needs.
  2. Mapping the retrieved Domain entities to ConsoleDomainInfo in memory, which avoids accessing and lazy-loading unused collections.
  3. Using 'LEFT JOIN FETCH d.statuses' and 'SELECT DISTINCT' in the JPQL query to eagerly load the domain statuses in a single query.
  4. Preserving the nested '@embeddable' JSON structure of 'creationTime' via 'CreateAutoTimestamp' in the DTO, maintaining 100% backward compatibility with the Angular frontend without requiring frontend changes.
  5. Updating all stream assertions in 'ConsoleDomainListActionTest' to reference 'ConsoleDomainInfo' and verifying that the entire test suite passes successfully.

TAG=agy
CONV=610c2358-a99f-4605-94cd-ff0d4ee08176


This change is Reviewable

@CydeWeys CydeWeys requested a review from ptkach June 26, 2026 14:24
@CydeWeys CydeWeys force-pushed the fix-domain-list-console branch from d2895f9 to 3d72918 Compare June 26, 2026 14:57
Optimize the domain list fetch action in the registrar console by implementing a lightweight DTO projection and a Two-Step Pagination Pattern.

Previously, ConsoleDomainListAction returned a paginated list of full Domain JPA entities. During Gson serialization, accessing lazy-loaded element collections (specifically 'statuses' and 'nsHosts') triggered a massive N+1 query loop, executing hundreds of secondary SQL queries per request. In a previous optimization attempt, adding a collection fetch join to the paginated query triggered Hibernate's silent in-memory pagination trap, which fetched all registrar domains into the App Engine JVM memory, causing severe performance issues on alpha.

This commit completely resolves the performance bottleneck by:
1. Introducing a lightweight 'ConsoleDomainInfo' DTO to expose only the five fields the frontend actually needs, avoiding loading unused heavy collections.
2. Implementing the Two-Step Pagination Pattern:
   - Step 1: Query the paginated page of domains (without collection fetch joins) to allow the database to execute a fast, native SQL LIMIT and OFFSET.
   - Step 2: Eagerly fetch the 'statuses' collection for only the returned page of domains (50 domains) using a single secondary query with an IN clause.
3. Mapping the results in memory to preserve the original sorted order and DTO structure, maintaining 100% backward compatibility with the Angular frontend.
4. Updating all stream assertions in 'ConsoleDomainListActionTest' to reference 'ConsoleDomainInfo' and verifying that the entire test suite passes successfully.

TAG=agy
CONV=610c2358-a99f-4605-94cd-ff0d4ee08176
@CydeWeys CydeWeys force-pushed the fix-domain-list-console branch from 3d72918 to cfe9ed1 Compare June 26, 2026 18:13
@CydeWeys

Copy link
Copy Markdown
Member Author

I'm not sure this is much of an improvement (if any), and it doesn't really seem to be helping things on alpha, so closing it for now.

@CydeWeys CydeWeys closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant