Skip to content

refactor: replace checklistRunner cache triples with a generic lazycache - #261

Merged
YoungJinJung merged 1 commit into
mainfrom
refactor/issue-204-checklist-lazycache
Aug 14, 2026
Merged

refactor: replace checklistRunner cache triples with a generic lazycache#261
YoungJinJung merged 1 commit into
mainfrom
refactor/issue-204-checklist-lazycache

Conversation

@YoungJinJung

Copy link
Copy Markdown
Contributor

Summary

Implements #204: checklistRunner repeated the same xLoaded bool / xErr error / xBy... map pattern seven times (RDS, hosted zones, VPCs, subnets, log groups, security groups, secrets).

  • New lazyCache[T] memoizes a single fetch — first Get runs the fetch once, later Gets return the same value and error without refetching (including memoized failures, matching the old behavior).
  • Each resource group's maps move into a small index struct (vpcIndex, subnetIndex, …) built inside the fetch closure.
  • Lookup logic (ID/name/ARN resolution, ambiguity errors, VPC scoping) is unchanged; the subnet loader still composes on the VPC loader through the cache.
  • secretDetails and zoneRecords stay as plain per-key maps — they are keyed caches, not load-once lists.

Testing

  • go test ./... passes; existing checklist tests cover the resolution behavior, and a new test pins the lazyCache contract (fetch-once, memoized value, memoized error, no retry).
  • make build passes.

Closes #204

Replace the seven repeated loaded/err/data field triples in
checklistRunner with a generic lazyCache[T] that memoizes a single
fetch (value and error) plus small per-resource index structs. Lookup
behavior is unchanged; the runner struct drops from 21 cache fields to
7 typed caches, and new checklist resource types no longer need to
hand-roll the load-once pattern.

Closes #204

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BFhLrnpVxivu62cC3k9NZB
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@YoungJinJung, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c368345d-8188-4b7d-b231-3da5d20ac1ea

📥 Commits

Reviewing files that changed from the base of the PR and between 744b139 and ddc81a3.

📒 Files selected for processing (2)
  • internal/inspector/checklist.go
  • internal/inspector/checklist_lazycache_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactoring successfully eliminates code duplication by introducing a generic lazyCache[T] pattern. The implementation correctly memoizes both successful values and errors, maintaining the same behavior as the original code. All existing tests pass, and new tests validate the cache contract. No defects found that would block merge.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@youngjinjung-linq youngjinjung-linq left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

과설계 관점 리뷰: 이 refactor는 반복 필드를 줄이지만 production diff가 오히려 24줄 순증가하고 일회성 타입 7개를 추가합니다.


// lazyCache memoizes a single fetch: the first Get runs fetch once, and every
// later Get returns the same value and error without refetching.
type lazyCache[T any] struct {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] yagni: generic lazyCache 하나를 넣기 위해 일회성 index wrapper 7개와 각 Get closure를 추가해 production code가 net +24 lines가 됐습니다. 기존 runner-local loaded/error/map triples가 못 해결하던 두 번째 사용처나 동시성 요구도 없습니다. 이 변경은 추상화 비용이 절감보다 큽니다; 적어도 wrapper types 없이 각 loader가 필요한 map 묶음을 직접 캐시하게 줄여 주세요. net: -24 lines possible.

@YoungJinJung

Copy link
Copy Markdown
Contributor Author

Addressed: dropped the generic lazyCache[T] and all seven index wrapper types. The per-resource maps are direct runner fields again (as on main); only the load-once bookkeeping is factored into a 12-line loadState whose do() memoizes both success and failure. The checklist file is now a net -8 production lines vs main instead of +24, and the seven loaded/err pairs are still gone.

@YoungJinJung
YoungJinJung merged commit 41b5439 into main Aug 14, 2026
5 checks passed
@YoungJinJung
YoungJinJung deleted the refactor/issue-204-checklist-lazycache branch August 14, 2026 00:24
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.

refactor: replace repeated loaded/err/data cache triples in checklistRunner with a generic lazycache

2 participants