Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Jan 8, 2026

Summary

  • Removes 60-second TTL caching from Docker container and network queries
  • Fixes stale data issues when containers are created/deleted externally (e.g., via CA)
  • Ensures API queries return live, up-to-date Docker state without requiring page refreshes

Test plan

  • Type checking passes (pnpm type-check)
  • All Docker-related tests pass
  • Verify container installs via CA appear immediately without refresh
  • Verify container deletions are reflected immediately without refresh

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Docker container and network information are now always fetched fresh from the API without caching, ensuring real-time accuracy.
  • Deprecations

    • The skipCache parameter for Docker queries is deprecated and ignored; caching functionality has been completely removed.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Walkthrough

Systematic removal of caching infrastructure from Docker services, including elimination of CACHE_MANAGER dependency, clearContainerCache method, skipCache parameters across service implementations, test files, and resolvers.

Changes

Cohort / File(s) Summary
Docker Service Core
api/src/unraid-api/graph/resolvers/docker/docker.service.ts, docker.service.spec.ts, docker.service.integration.spec.ts
Removed CACHE_MANAGER injection, cache constants, and clearContainerCache method. Simplified getContainers, getPortConflicts, and getNetworks signatures by removing skipCache parameters. Updated all tests to remove cache mocking and call sites.
Docker Event Service
api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts, docker-event.service.spec.ts
Removed clearContainerCache calls and related mock assertions. Container event handling now directly fetches app info without cache invalidation.
Docker Network Service
api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts, docker-network.service.spec.ts
Removed CACHE_MANAGER dependency and caching logic. Simplified getNetworks from skipCache-aware method to parameter-less function with direct Docker fetch path.
Docker Resolver
api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts, docker.resolver.spec.ts
Deprecated skipCache arguments in containers, networks, portConflicts, and organizer fields with deprecationReason messages. Removed clearContainerCache call from resetDockerTemplateMappings. Updated internal calls to drop skipCache usage.
Docker Organizer Service
api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts
Removed skipCache parameter from getResources, syncAndGetOrganizer, and resolveOrganizer method signatures. Internal calls now use simplified parameter-less variants.
Docker Template Scanner
api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts
Updated getContainers call to remove skipCache option usage.
Docker Module Tests
api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
Replaced clearContainerCache mock with empty object in DockerService fixture setup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Cache be gone, the data flows so free,
No more stashing, fresh each query be,
Docker services lean and light,
Parameters pruned, signatures tight! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(docker): remove aggressive caching to ensure data correctness' directly and accurately summarizes the main change across all files: removing caching mechanisms from Docker services to prevent stale data issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

this.logger.debug(`Invalidated container caches after stopping ${id}`);

let containers = await this.getContainers({ skipCache: true });
let containers = await this.getContainers();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

The initial value of containers is unused, since it is always overwritten.

Copilot Autofix

AI 24 days ago

In general, to fix a “useless assignment to local variable” you either (a) remove the unnecessary assignment if the value is truly unused, or (b) start using the initially assigned value in the logic if it was meant to be used but wasn’t. You must ensure that any required side effects from the right-hand side expression are still executed somewhere if they matter.

Here, the initial assignment let containers = await this.getContainers(); is never read before containers is reassigned in the loop. The method’s logic only relies on the values retrieved inside the loop. The simplest and safest fix is to declare containers without an initial value, and continue to assign to it inside the loop. That way, we preserve the same number and timing of this.getContainers() calls (still called once per loop iteration after a sleep) while eliminating the useless initial call and assignment.

Concretely, in api/src/unraid-api/graph/resolvers/docker/docker.service.ts, in the stop method around line 239, change let containers = await this.getContainers(); to let containers: DockerContainer[] = []; (or just let containers: DockerContainer[]; if you prefer leaving it undefined until first use). This keeps type information clear and avoids any unused initial value. No new imports or additional methods are required.

Suggested changeset 1
api/src/unraid-api/graph/resolvers/docker/docker.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api/src/unraid-api/graph/resolvers/docker/docker.service.ts b/api/src/unraid-api/graph/resolvers/docker/docker.service.ts
--- a/api/src/unraid-api/graph/resolvers/docker/docker.service.ts
+++ b/api/src/unraid-api/graph/resolvers/docker/docker.service.ts
@@ -236,7 +236,7 @@
         const container = this.client.getContainer(id);
         await container.stop({ t: 10 });
 
-        let containers = await this.getContainers();
+        let containers: DockerContainer[];
         let updatedContainer: DockerContainer | undefined;
         for (let i = 0; i < 5; i++) {
             await sleep(500);
EOF
@@ -236,7 +236,7 @@
const container = this.client.getContainer(id);
await container.stop({ t: 10 });

let containers = await this.getContainers();
let containers: DockerContainer[];
let updatedContainer: DockerContainer | undefined;
for (let i = 0; i < 5; i++) {
await sleep(500);
Copilot is powered by AI and may make mistakes. Always verify output.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1864/dynamix.unraid.net.plg

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 54.38596% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.44%. Comparing base (9ef1cf1) to head (8c984b5).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...raid-api/graph/resolvers/docker/docker.resolver.ts 36.00% 16 Missing ⚠️
...nraid-api/graph/resolvers/docker/docker.service.ts 57.14% 9 Missing ⚠️
...lvers/docker/organizer/docker-organizer.service.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1864      +/-   ##
==========================================
- Coverage   46.49%   46.44%   -0.06%     
==========================================
  Files         954      954              
  Lines       59788    59730      -58     
  Branches     5552     5541      -11     
==========================================
- Hits        27799    27741      -58     
  Misses      31870    31870              
  Partials      119      119              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts:
- Around line 78-82: The container resolver currently fetches all containers via
dockerService.getContainers() and doesn't pass the Docker API size option when
the GraphQL fields sizeRootFs/sizeRw are requested; update the container method
to inspect the GraphQLResolveInfo (add an info parameter) to detect if
sizeRootFs or sizeRw are requested and then call a single-container fetch that
accepts the size flag (e.g., dockerService.getContainer(id, { size: true }) or
dockerService.getContainers({ id, size: true }) depending on available service
methods) so the Docker API returns populated sizeRootFs/sizeRw fields; keep
returning the found container or null.
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ef1cf1 and 8c984b5.

📒 Files selected for processing (12)
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts
  • api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts
💤 Files with no reviewable changes (1)
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.spec.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Always use TypeScript imports with .js extensions for ESM compatibility
Never add comments unless they are needed for clarity of function
Never add comments for obvious things, and avoid commenting when starting and ending code blocks

Files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts
  • api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
api/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts
  • api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Never use the any type. Always prefer proper typing
Avoid using casting whenever possible, prefer proper typing from the start

Files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts
  • api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
api/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

cache-manager v7 expects TTL values in milliseconds, not seconds (e.g., 600000 for 10 minutes, not 600)

Files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts
  • api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
**/*

📄 CodeRabbit inference engine (.cursor/rules/default.mdc)

Never add comments unless they are needed for clarity of function

Files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts
  • api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
🧠 Learnings (16)
📚 Learning: 2025-11-24T17:52:26.907Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.907Z
Learning: Applies to **/*.test.ts : Mock external services and API calls

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
📚 Learning: 2025-11-24T17:51:46.348Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-11-24T17:51:46.348Z
Learning: Applies to api/**/*.test.{ts,tsx} : Prefer to not mock simple dependencies

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
📚 Learning: 2025-11-24T17:52:26.908Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.908Z
Learning: Applies to **/__test__/store/**/*.ts : Mock external dependencies appropriately in Pinia store tests

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
📚 Learning: 2025-11-24T17:52:26.907Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.907Z
Learning: Applies to **/*.test.ts : Use `vi.mock()` for module-level mocks

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
📚 Learning: 2025-08-09T01:03:29.676Z
Learnt from: elibosley
Repo: unraid/api PR: 1575
File: packages/unraid-shared/src/services/socket-config.service.spec.ts:10-13
Timestamp: 2025-08-09T01:03:29.676Z
Learning: Vitest is used for all testing across all repositories in the unraid organization, not Jest. Always use `vi` for mocking utilities, not `jest`.

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
📚 Learning: 2025-11-24T17:52:26.907Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.907Z
Learning: Applies to **/*.test.ts : Reset mocks between tests with `vi.clearAllMocks()`

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
📚 Learning: 2025-11-24T17:52:26.907Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.907Z
Learning: Applies to **/__test__/components/**/*.ts : Mock external dependencies and services in Vue component tests

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
📚 Learning: 2025-11-24T17:52:26.908Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.908Z
Learning: Applies to **/__test__/store/**/*.ts : Use factory functions for module mocks in Pinia store tests to avoid hoisting issues

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts
📚 Learning: 2025-11-24T17:52:26.908Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.908Z
Learning: Applies to **/__test__/store/**/*.ts : Test Pinia store getter dependencies are properly mocked

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts
📚 Learning: 2025-11-24T17:52:26.908Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.908Z
Learning: Applies to **/__test__/store/**/*.ts : Use `createPinia()` instead of `createTestingPinia()` for most Pinia store tests

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
📚 Learning: 2025-11-24T17:51:37.915Z
Learnt from: CR
Repo: unraid/api PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T17:51:37.915Z
Learning: Applies to web/__test__/**/*.test.{ts,tsx} : Use `createPinia()` and `setActivePinia` when testing Store files, only use `createTestingPinia` if you specifically need its testing features

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts
📚 Learning: 2025-11-24T17:52:26.907Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.907Z
Learning: This is a Nuxt.js app but tests are run with vitest outside of the Nuxt environment

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
📚 Learning: 2025-11-24T17:51:46.348Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-11-24T17:51:46.348Z
Learning: Applies to api/**/*.test.{ts,tsx} : Use Vitest for the test suite, not Jest

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
📚 Learning: 2025-11-24T17:52:26.907Z
Learnt from: CR
Repo: unraid/api PR: 0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-11-24T17:52:26.907Z
Learning: Applies to **/__test__/components/**/*.ts : Use `createTestingPinia()` for mocking stores in Vue components

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts
📚 Learning: 2025-04-07T14:34:47.255Z
Learnt from: elibosley
Repo: unraid/api PR: 1334
File: api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts:63-66
Timestamp: 2025-04-07T14:34:47.255Z
Learning: In DockerEventService, the chokidar file watcher is configured with `ignoreInitial: false` to ensure that existing files (like the Docker socket) are detected and processed at application startup, not just when files change after the watcher is initialized.

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts
📚 Learning: 2024-11-06T20:59:25.809Z
Learnt from: mdatelle
Repo: unraid/api PR: 942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.

Applied to files:

  • api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts
🧬 Code graph analysis (4)
api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts (3)
api/src/unraid-api/graph/resolvers/docker/utils/docker-client.ts (1)
  • getDockerClient (5-12)
api/src/unraid-api/cli/generated/graphql.ts (1)
  • DockerNetwork (900-917)
web/src/composables/gql/graphql.ts (1)
  • DockerNetwork (924-941)
api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts (1)
api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts (1)
  • organizer (178-187)
api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts (1)
api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts (2)
  • containers (89-122)
  • networks (145-154)
api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts (1)
api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts (1)
  • containers (89-122)
🪛 GitHub Check: CodeQL
api/src/unraid-api/graph/resolvers/docker/docker.service.ts

[warning] 239-239: Useless assignment to local variable
The initial value of containers is unused, since it is always overwritten.

🔇 Additional comments (22)
api/src/unraid-api/graph/resolvers/docker/docker.service.spec.ts (1)

276-276: LGTM! Tests correctly updated to reflect cache removal.

The tests now verify direct Docker API interactions via mockListContainers instead of cache-related behavior, which aligns with the PR objective to eliminate the 60-second TTL cache.

Also applies to: 319-345

api/src/unraid-api/graph/resolvers/docker/docker.service.ts (4)

1-1: LGTM! Cache manager successfully removed from service.

The removal of CACHE_MANAGER injection and related imports correctly implements the PR objective to eliminate Docker caching infrastructure.

Also applies to: 32-41


128-160: Signature change ensures fresh data on every call.

The updated getContainers signature now uses Docker.ContainerListOptions directly (with defaults all=true, size=false) and removes the cache abstraction. This guarantees API queries return live Docker state, addressing the stale-data issues mentioned in the PR objectives.


162-165: Port conflicts and networks now fetch fresh data.

Both getPortConflicts and getNetworks methods now always fetch live data without cache parameters, ensuring changes from external tools (like Community Applications) are immediately visible.

Also applies to: 182-184


239-239: CodeQL false positive can be safely ignored.

The static analysis warning about "useless assignment" at line 239 is a false positive. The containers variable is intentionally reassigned in the retry loop (line 243) to poll for updated container state after the stop command.

api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts (1)

90-90: Template scanner now uses live container data.

Calling getContainers() without skipCache ensures the template scanner sees the most current container state, preventing mismatches when containers are added/removed externally.

api/src/unraid-api/graph/resolvers/docker/docker.module.spec.ts (1)

76-76: Mock correctly updated to reflect removed method.

The DockerService mock no longer includes clearContainerCache, which aligns with its removal from the actual service implementation.

api/src/unraid-api/graph/resolvers/docker/docker-event.service.ts (1)

127-136: Event handler now publishes fresh app info.

Removing the cache-clearing step and directly calling getAppInfo() ensures Docker events (start, stop, etc.) trigger immediate fresh data fetches. This guarantees the published app info reflects the actual current state.

api/src/unraid-api/graph/resolvers/docker/docker.service.integration.spec.ts (2)

70-81: LGTM - Cache manager correctly removed from test setup.

The test module no longer provides CACHE_MANAGER, which aligns with the service's removal of cache dependencies. The setup now includes only the necessary service providers for integration testing.


94-94: LGTM - Method calls updated to reflect no-cache API.

All Docker service method calls have been correctly updated to omit the skipCache parameter, ensuring integration tests validate direct Docker daemon interaction as intended by this PR.

Also applies to: 104-104, 113-113, 145-145

api/src/unraid-api/graph/resolvers/docker/docker-network.service.spec.ts (3)

22-30: LGTM - Test module simplified correctly.

The test setup has been streamlined to remove the CACHE_MANAGER provider, reflecting the service's removal of cache dependencies. The module now contains only the essential DockerNetworkService provider.


37-52: LGTM - Test correctly validates direct Docker fetch.

The test has been appropriately updated to:

  • Call getNetworks() without cache-related parameters
  • Verify the camelCase property name (correctly mapped from Docker's Name)
  • Focus on direct Docker API interaction

54-60: LGTM - Good edge case coverage.

The test appropriately validates the empty array case when no Docker networks exist, ensuring the service handles this scenario correctly without cache fallback.

api/src/unraid-api/graph/resolvers/docker/docker.resolver.spec.ts (2)

163-163: LGTM - Test expectations correctly updated.

All test expectations have been properly updated to reflect the removal of skipCache from the getContainers method signature. The tests now validate calls with only the size parameter, which is correct.

Also applies to: 193-193, 207-207, 242-242, 256-256, 268-268


271-281: LGTM - Excellent deprecation test.

This test effectively documents that the skipCache parameter is now deprecated and ignored, providing clear evidence of the API behavior change while maintaining backward compatibility.

api/src/unraid-api/graph/resolvers/docker/docker-network.service.ts (1)

1-42: LGTM - Clean cache removal implementation.

The service has been successfully refactored to remove all caching infrastructure:

  • Eliminated CACHE_MANAGER dependency
  • Simplified getNetworks() to always fetch live data
  • Updated logging to reflect direct Docker API calls

This ensures Docker network queries always return current state, addressing the stale-data issues described in the PR objectives.

api/src/unraid-api/graph/resolvers/docker/organizer/docker-organizer.service.ts (1)

57-90: LGTM - Organizer service correctly updated.

The organizer service methods have been properly refactored to remove skipCache parameters throughout the call chain:

  • getResources now passes options directly to dockerService.getContainers without cache-related spreading
  • syncAndGetOrganizer and resolveOrganizer have simplified signatures without cache options
  • The changes maintain functionality while removing cache complexity
api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts (5)

89-122: LGTM! Clean deprecation with correct service integration.

The skipCache parameter is properly deprecated with a clear reason, and the service call correctly removes caching while preserving the conditional size option based on requested fields. The field inspection logic via @Info() remains intact and appropriate.


145-154: LGTM! Consistent deprecation pattern.

The deprecation and service call update align with the caching removal objective.


161-170: LGTM! Consistent deprecation pattern.

The deprecation and service call update align with the caching removal objective.


178-187: LGTM! Consistent deprecation pattern.

The deprecation and service call update align with the caching removal objective.


363-374: LGTM! Cache clearing removed as intended.

The removal of the clearContainerCache() call is consistent with the PR objective to eliminate caching infrastructure. The mutation still correctly resets template mappings to defaults.

Comment on lines 78 to 82
@ResolveField(() => DockerContainer, { nullable: true })
public async container(@Args('id', { type: () => PrefixedID }) id: string) {
const containers = await this.dockerService.getContainers({ skipCache: false });
const containers = await this.dockerService.getContainers();
return containers.find((c) => c.id === id) ?? null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add size field handling for consistency with the containers method.

The container resolver doesn't check whether size fields (sizeRootFs, sizeRw) are requested, unlike the containers method (lines 98-103). This means if a client queries docker.container(id: "...") { sizeRootFs }, the field won't be populated correctly because the Docker API requires an explicit size option.

🔧 Suggested fix to match `containers` behavior
 @ResolveField(() => DockerContainer, { nullable: true })
-public async container(@Args('id', { type: () => PrefixedID }) id: string) {
-    const containers = await this.dockerService.getContainers();
+public async container(
+    @Args('id', { type: () => PrefixedID }) id: string,
+    @Info() info: GraphQLResolveInfo
+) {
+    const requestsRootFsSize = GraphQLFieldHelper.isFieldRequested(info, 'sizeRootFs');
+    const requestsRwSize = GraphQLFieldHelper.isFieldRequested(info, 'sizeRw');
+    const containers = await this.dockerService.getContainers({
+        size: requestsRootFsSize || requestsRwSize,
+    });
     return containers.find((c) => c.id === id) ?? null;
 }
🤖 Prompt for AI Agents
In @api/src/unraid-api/graph/resolvers/docker/docker.resolver.ts around lines 78
- 82, The container resolver currently fetches all containers via
dockerService.getContainers() and doesn't pass the Docker API size option when
the GraphQL fields sizeRootFs/sizeRw are requested; update the container method
to inspect the GraphQLResolveInfo (add an info parameter) to detect if
sizeRootFs or sizeRw are requested and then call a single-container fetch that
accepts the size flag (e.g., dockerService.getContainer(id, { size: true }) or
dockerService.getContainers({ id, size: true }) depending on available service
methods) so the Docker API returns populated sizeRootFs/sizeRw fields; keep
returning the found container or null.

@pujitm pujitm merged commit 1c1bae8 into main Jan 9, 2026
13 checks passed
@pujitm pujitm deleted the fix/docker-caching branch January 9, 2026 17:55
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.

3 participants