Skip to content

feat(groundcontrol): Implement in-memory cache for satellite group st… - #613

Draft
Dishank-Sen wants to merge 3 commits into
container-registry:mainfrom
Dishank-Sen:feat/groundcontrol-group-states-cache
Draft

feat(groundcontrol): Implement in-memory cache for satellite group st…#613
Dishank-Sen wants to merge 3 commits into
container-registry:mainfrom
Dishank-Sen:feat/groundcontrol-group-states-cache

Conversation

@Dishank-Sen

@Dishank-Sen Dishank-Sen commented Aug 11, 2026

Copy link
Copy Markdown

Fixes: #583

Description

Implements an in-memory cache for satellite group states in Ground Control, addressing the TODO in SetSatelliteConfig (config_handlers.go:489).

Previously, every call to SetSatelliteConfig queried the database for all groups a satellite belongs to and fetched each group's details individually. The cache is keyed by satellite ID, protected by an RWMutex, and kept consistent across group modification operations.

Additional context

Cache is invalidated/updated in RegisterSatellite, AddSatelliteToGroup, RemoveSatelliteFromGroup, DeleteSatellite, and DeleteGroup. Unit tests added in groupstates_cache_test.go covering get/set roundtrips, invalidation, and per-satellite isolation.

Review in cubic

Summary by CodeRabbit

  • Performance
    • Improved satellite configuration and group-state operations by using an in-memory cache, reducing repeated database lookups.
  • Reliability
    • Kept cached group-state data synchronized as satellites and groups are added, removed, updated, or deleted.
    • Added safe cache invalidation when satellite records are removed, with database fallback when cached data is unavailable.
  • Testing
    • Added coverage for cache reads, updates, invalidation, empty states, and independent satellite entries.

…ates

Signed-off-by: Dishank-Sen <dishanksen05@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

Next review available in: 19 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e6d905cd-e81e-4d5d-a461-2e5982f6a757

📥 Commits

Reviewing files that changed from the base of the PR and between cc5bf39 and 05a4059.

📒 Files selected for processing (3)
  • internal/groundcontrol/server/group_handlers.go
  • internal/groundcontrol/server/groupstates_cache_test.go
  • internal/groundcontrol/server/helpers.go
📝 Walkthrough

Walkthrough

The Ground Control server adds a synchronized in-memory cache for satellite group states. Lifecycle handlers refresh or invalidate entries, and SetSatelliteConfig uses cached states with database fallback.

Changes

Satellite group-state caching

Layer / File(s) Summary
Cache storage and database fallback
internal/groundcontrol/server/server.go, internal/groundcontrol/server/helpers.go, internal/groundcontrol/server/groupstates_cache_test.go
The server initializes a mutex-protected cache. Helper methods read, store, invalidate, and populate satellite group states. Tests cover cache operations and satellite isolation.
Lifecycle cache synchronization
internal/groundcontrol/server/satellite_handlers.go, internal/groundcontrol/server/group_handlers.go
Satellite registration and group membership changes refresh cached states. Satellite deletion invalidates its entry. Group deletion stores recalculated states.
Cached configuration lookup
internal/groundcontrol/server/config_handlers.go
SetSatelliteConfig reads cached group states and falls back to database retrieval when needed. Fetch errors retain the internal-server-error response path.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SetSatelliteConfig
  participant GroupStatesCache
  participant Database
  SetSatelliteConfig->>GroupStatesCache: Read satellite group states
  GroupStatesCache-->>SetSatelliteConfig: Return cached states on hit
  SetSatelliteConfig->>Database: Retrieve groups on cache miss
  Database-->>SetSatelliteConfig: Return group data or lookup error
  SetSatelliteConfig->>GroupStatesCache: Store successful group states
Loading

Suggested labels: enhancement

Suggested reviewers: bupd

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the implementation of the in-memory satellite group-state cache.
Description check ✅ Passed The description includes all template sections and explains the cache design, affected handlers, and added tests.
Linked Issues check ✅ Passed The changes implement the linked issue requirements for caching, database fallback, synchronization, and lifecycle updates.
Out of Scope Changes check ✅ Passed The changes remain focused on the satellite group-state cache and its lifecycle behavior; no unrelated scope is evident.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@gitar-bot

gitar-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

Gitar is working

Gitar

@codacy-production

codacy-production Bot commented Aug 11, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 38 complexity · 1 duplication

Metric Results
Complexity 38
Duplication 1

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/groundcontrol/server/group_handlers.go`:
- Around line 287-289: Update the group deletion flow around
setGroupStatesCache, q.DeleteGroup, and tx.Commit so recalculated states are
held in a local map during the transaction rather than written to the cache
immediately. Only populate the cache after tx.Commit succeeds, preserving the
existing state updates and leaving the cache unchanged when deletion or commit
fails.

In `@internal/groundcontrol/server/helpers.go`:
- Around line 411-415: Update getGroupStatesFromCache to return both the cached
[]string and a map-presence boolean, distinguishing cached nil/empty states from
missing satelliteID entries. Modify SetSatelliteConfig to use the boolean for
cache-hit decisions, and add coverage for a cached nil or empty group-state
entry to ensure database queries are not repeated.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b6f0a1ea-0d53-4aa2-b087-1b66e5d44e32

📥 Commits

Reviewing files that changed from the base of the PR and between 341cb42 and aaf208d.

📒 Files selected for processing (6)
  • internal/groundcontrol/server/config_handlers.go
  • internal/groundcontrol/server/group_handlers.go
  • internal/groundcontrol/server/groupstates_cache_test.go
  • internal/groundcontrol/server/helpers.go
  • internal/groundcontrol/server/satellite_handlers.go
  • internal/groundcontrol/server/server.go

Comment thread internal/groundcontrol/server/group_handlers.go Outdated
Comment thread internal/groundcontrol/server/helpers.go

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/groundcontrol/server/helpers.go Outdated
Comment thread internal/groundcontrol/server/group_handlers.go Outdated
Comment thread internal/groundcontrol/server/config_handlers.go
Comment thread internal/groundcontrol/server/groupstates_cache_test.go
Comment thread internal/groundcontrol/server/helpers.go

@Dishank-Sen Dishank-Sen left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have reviewed all the suggestion and made appropriate fixes.

Signed-off-by: Dishank-Sen <dishanksen05@gmail.com>

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/groundcontrol/server/helpers.go Outdated
Comment thread internal/groundcontrol/server/group_handlers.go Outdated
Signed-off-by: Dishank-Sen <dishanksen05@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(groundcontrol): Implement in-memory cache for satellite group states

1 participant