Skip to content

Chore: Simplify Settings-Handling#667

Open
JW-CH wants to merge 2 commits into
mainfrom
settings_cleanup
Open

Chore: Simplify Settings-Handling#667
JW-CH wants to merge 2 commits into
mainfrom
settings_cleanup

Conversation

@JW-CH

@JW-CH JW-CH commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Configuration endpoint now returns a client-facing settings projection only, supporting cleaner separation of server vs. client options.
    • Updated API schema generation so read-only variants are no longer produced for the client settings response.
  • Bug Fixes

    • Improved multi-account image selection when no accounts exist or when all accounts report zero assets.
    • Enhanced asset-location tracking reliability under concurrent requests.
  • Tests

    • Added/expanded automated coverage for configuration output and secret redaction, plus account image-selection behavior.

…safe, change construction of account strategy
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 14f1abbb-933e-4b94-ab4b-b8821113938f

📥 Commits

Reviewing files that changed from the base of the PR and between cbb9d08 and f146783.

📒 Files selected for processing (4)
  • ImmichFrame.Core.Tests/Logic/AccountSelection/TotalAccountImagesSelectionStrategyTests.cs
  • ImmichFrame.Core/Logic/AccountSelection/BloomFilterAssetAccountTracker.cs
  • ImmichFrame.Core/Logic/AccountSelection/TotalAccountImagesSelectionStrategy.cs
  • ImmichFrame.WebApi/Helpers/NoReadOnlySchemaFilter.cs
🚧 Files skipped from review as they are similar to previous changes (4)
  • ImmichFrame.WebApi/Helpers/NoReadOnlySchemaFilter.cs
  • ImmichFrame.Core/Logic/AccountSelection/TotalAccountImagesSelectionStrategy.cs
  • ImmichFrame.Core.Tests/Logic/AccountSelection/TotalAccountImagesSelectionStrategyTests.cs
  • ImmichFrame.Core/Logic/AccountSelection/BloomFilterAssetAccountTracker.cs

📝 Walkthrough

Walkthrough

This PR splits settings contracts, updates the config DTO/controller and Swagger wiring, refactors account-selection construction and tracking, adds tests, and removes an unused collection helper.

Changes

Settings interface split and DTO/controller wiring

Layer / File(s) Summary
Settings contracts
ImmichFrame.Core/Interfaces/IClientSettings.cs, ImmichFrame.Core/Interfaces/IServerBehaviorSettings.cs, ImmichFrame.Core/Interfaces/IServerSettings.cs
Introduces IClientSettings and IServerBehaviorSettings, and makes IGeneralSettings inherit both.
Config DTO and controller
ImmichFrame.WebApi/Models/ClientSettingsDto.cs, ImmichFrame.WebApi/Controllers/ConfigController.cs
ClientSettingsDto becomes a read-only projection over IClientSettings, and ConfigController now depends on IClientSettings and constructs the DTO directly.
DI, Swagger, and config tests
ImmichFrame.WebApi/Program.cs, ImmichFrame.WebApi/Helpers/NoReadOnlySchemaFilter.cs, ImmichFrame.WebApi.Tests/Controllers/ConfigControllerTests.cs
Registers the split settings interfaces, applies the schema filter for ClientSettingsDto, and adds tests for the config response and secret exclusion.

Account selection strategy and tracker refactor

Layer / File(s) Summary
Strategy construction and proportions
ImmichFrame.Core/Interfaces/IImmichFrameLogic.cs, ImmichFrame.Core/Logic/AccountSelection/TotalAccountImagesSelectionStrategy.cs
Removes Initialize, passes accounts through the constructor, and handles zero totals without producing NaN proportions.
Delegate wiring and strategy tests
ImmichFrame.Core/Logic/MultiImmichFrameLogicDelegate.cs, ImmichFrame.Core.Tests/Logic/AccountSelection/TotalAccountImagesSelectionStrategyTests.cs
MultiImmichFrameLogicDelegate now creates the strategy through a factory, and tests cover empty, uneven, and tracker-recording behavior.
Bloom filter tracker and helper cleanup
ImmichFrame.Core/Logic/AccountSelection/BloomFilterAssetAccountTracker.cs, ImmichFrame.Core/Helpers/CollectionExtensionMethods.cs
Tracker caching now uses concurrent lazy filter creation, membership checks read from the task-backed filters, and GetOrCreateAsync is removed.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • immichFrame/ImmichFrame#511: Changes the same settings interface area around IGeneralSettings and related configuration contracts.
  • immichFrame/ImmichFrame#654: Touches the same account-selection code paths, including TotalAccountImagesSelectionStrategy and BloomFilterAssetAccountTracker.

Suggested labels: breaking-change

Suggested reviewers: 3rob3

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main theme of the PR: simplifying and restructuring settings handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch settings_cleanup

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.

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
ImmichFrame.WebApi/Helpers/NoReadOnlySchemaFilter.cs (1)

14-20: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider scoping the filter instead of applying it globally.

This filter strips ReadOnly from every schema property app-wide, not just the get-only DTOs (like ClientSettingsDto) it was designed for. If a future response/request type legitimately needs readOnly (e.g., a server-assigned ID field), this filter will silently suppress that signal in the generated OpenAPI doc/client.

♻️ Optional: scope to specific types
 public void Apply(OpenApiSchema schema, SchemaFilterContext context)
 {
+    if (context.Type != typeof(Models.ClientSettingsDto))
+        return;
+
     foreach (var property in schema.Properties.Values)
     {
         property.ReadOnly = false;
     }
 }
🤖 Prompt for 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.

In `@ImmichFrame.WebApi/Helpers/NoReadOnlySchemaFilter.cs` around lines 14 - 20,
The NoReadOnlySchemaFilter is currently clearing ReadOnly on every OpenApiSchema
property, which makes it too broad for its intended use. Update Apply in
NoReadOnlySchemaFilter to only strip ReadOnly for the specific DTO types it was
meant to handle, such as ClientSettingsDto or other get-only response models, by
checking SchemaFilterContext before mutating schema.Properties. Keep the
filter’s behavior limited to those targeted types so legitimate readOnly fields
in other schemas remain intact.
ImmichFrame.Core.Tests/Logic/AccountSelection/TotalAccountImagesSelectionStrategyTests.cs (1)

42-52: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider adding a zero-accounts test case.

Existing coverage handles accounts with zero total assets, but not a fully empty account list (CreateStrategy() with no args), which is the scenario that still throws in GetAssets() per the related comment in TotalAccountImagesSelectionStrategy.cs.

🤖 Prompt for 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.

In
`@ImmichFrame.Core.Tests/Logic/AccountSelection/TotalAccountImagesSelectionStrategyTests.cs`
around lines 42 - 52, Add a test for the fully empty account list scenario in
TotalAccountImagesSelectionStrategyTests, since GetAssets() still fails when
CreateStrategy() is called with no accounts. Extend the existing coverage around
GetAssets and CreateStrategy to verify that an empty strategy returns an empty
result without throwing or producing NaN, alongside the current
zero-total-assets case.
🤖 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 `@ImmichFrame.Core/Logic/AccountSelection/BloomFilterAssetAccountTracker.cs`:
- Around line 13-18: The filter cache in
BloomFilterAssetAccountTracker.RecordAssetLocation is retaining failed
Lazy<Task<IBloomFilter>> entries from NewFilter(account), causing later calls to
reuse the same faulted task. Update the logic around logicToFilter.GetOrAdd so
that if the filter creation task fails, the entry for that
IAccountImmichFrameLogic is removed from logicToFilter before the exception is
propagated, allowing a fresh filter build on the next RecordAssetLocation or
ForAsset attempt.

In
`@ImmichFrame.Core/Logic/AccountSelection/TotalAccountImagesSelectionStrategy.cs`:
- Around line 34-45: GetProportions() still allows GetAssets() to call Max() on
an empty sequence when accounts is empty, causing InvalidOperationException.
Update TotalAccountImagesSelectionStrategy.GetAssets() to short-circuit before
calling Max() and return Enumerable.Empty<(IAccountImmichFrameLogic,
AssetResponseDto)>() when there are no accounts, using the existing
GetProportions() and GetWeights() flow only for non-empty account lists.

---

Nitpick comments:
In
`@ImmichFrame.Core.Tests/Logic/AccountSelection/TotalAccountImagesSelectionStrategyTests.cs`:
- Around line 42-52: Add a test for the fully empty account list scenario in
TotalAccountImagesSelectionStrategyTests, since GetAssets() still fails when
CreateStrategy() is called with no accounts. Extend the existing coverage around
GetAssets and CreateStrategy to verify that an empty strategy returns an empty
result without throwing or producing NaN, alongside the current
zero-total-assets case.

In `@ImmichFrame.WebApi/Helpers/NoReadOnlySchemaFilter.cs`:
- Around line 14-20: The NoReadOnlySchemaFilter is currently clearing ReadOnly
on every OpenApiSchema property, which makes it too broad for its intended use.
Update Apply in NoReadOnlySchemaFilter to only strip ReadOnly for the specific
DTO types it was meant to handle, such as ClientSettingsDto or other get-only
response models, by checking SchemaFilterContext before mutating
schema.Properties. Keep the filter’s behavior limited to those targeted types so
legitimate readOnly fields in other schemas remain intact.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: deb2ae9e-aee6-418b-8848-7ef770140c27

📥 Commits

Reviewing files that changed from the base of the PR and between 682fdc4 and cbb9d08.

📒 Files selected for processing (14)
  • ImmichFrame.Core.Tests/Logic/AccountSelection/TotalAccountImagesSelectionStrategyTests.cs
  • ImmichFrame.Core/Helpers/CollectionExtensionMethods.cs
  • ImmichFrame.Core/Interfaces/IClientSettings.cs
  • ImmichFrame.Core/Interfaces/IImmichFrameLogic.cs
  • ImmichFrame.Core/Interfaces/IServerBehaviorSettings.cs
  • ImmichFrame.Core/Interfaces/IServerSettings.cs
  • ImmichFrame.Core/Logic/AccountSelection/BloomFilterAssetAccountTracker.cs
  • ImmichFrame.Core/Logic/AccountSelection/TotalAccountImagesSelectionStrategy.cs
  • ImmichFrame.Core/Logic/MultiImmichFrameLogicDelegate.cs
  • ImmichFrame.WebApi.Tests/Controllers/ConfigControllerTests.cs
  • ImmichFrame.WebApi/Controllers/ConfigController.cs
  • ImmichFrame.WebApi/Helpers/NoReadOnlySchemaFilter.cs
  • ImmichFrame.WebApi/Models/ClientSettingsDto.cs
  • ImmichFrame.WebApi/Program.cs
💤 Files with no reviewable changes (2)
  • ImmichFrame.Core/Interfaces/IImmichFrameLogic.cs
  • ImmichFrame.Core/Helpers/CollectionExtensionMethods.cs

Comment thread ImmichFrame.Core/Logic/AccountSelection/BloomFilterAssetAccountTracker.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant