Skip to content

Refactor SettingsBase cache lookup to use explicit LINQ filtering#1149

Merged
glennawatson merged 8 commits intoUpdateSettingsfrom
copilot/sub-pr-1147-again
Dec 4, 2025
Merged

Refactor SettingsBase cache lookup to use explicit LINQ filtering#1149
glennawatson merged 8 commits intoUpdateSettingsfrom
copilot/sub-pr-1147-again

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

Addresses feedback on #1147 to replace implicit filtering within a foreach loop with explicit LINQ filtering.

Changes

  • Replaced foreach with FirstOrDefault: Changed implicit if (kvp.Value != null) check inside loop to explicit .FirstOrDefault(kvp => kvp.Value != null) predicate
  • Safer null handling: Check firstPair.Key instead of firstPair.Value to distinguish actual dictionary entries from default KeyValuePair struct
  • Added System.Linq using: Required for LINQ extension methods

Before/After

// Before: implicit filtering
foreach (var kvp in AkavacheBuilder.BlobCaches)
{
    if (kvp.Value != null)
    {
        return kvp.Value;
    }
}

// After: explicit filtering
var firstPair = AkavacheBuilder.BlobCaches
    .FirstOrDefault(kvp => kvp.Value != null);

if (!string.IsNullOrEmpty(firstPair.Key))
{
    return firstPair.Value!;
}

The fallback chain to CacheDatabase caches remains unchanged when no cache is found in AkavacheBuilder.BlobCaches.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits December 4, 2025 22:45
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Copilot AI changed the title [WIP] Add response to feedback on SettingsBase refactor Refactor SettingsBase cache lookup to use explicit LINQ filtering Dec 4, 2025
Copilot AI requested a review from ChrisPulman December 4, 2025 23:00
@glennawatson glennawatson marked this pull request as ready for review December 4, 2025 23:54
@glennawatson glennawatson merged commit 154c0d8 into UpdateSettings Dec 4, 2025
@glennawatson glennawatson deleted the copilot/sub-pr-1147-again branch December 4, 2025 23:55
ChrisPulman added a commit that referenced this pull request Dec 5, 2025
* Refactor SettingsBase to use primary constructor and improve cache selection

Refactored SettingsBase to use a C# primary constructor and updated the logic for selecting the appropriate IBlobCache. The new logic prioritizes explicitly created caches, falls back to CacheDatabase caches, and finally creates an in-memory cache if a serializer is available. Improved error handling and exception messages for missing caches.

* Update CI workflow to run PRs on main branch

The CI workflow now runs on pull requests targeting the main branch. Added global environment variable for productNamespacePrefix and set build configuration to Release.

* Update src/Akavache.Settings/SettingsBase.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update .github/workflows/ci-build.yml

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add test coverage for SettingsBase cache fallback logic (#1148)

* Initial plan

* Add test coverage for SettingsBase fallback logic

- Tests verify fallback to CacheDatabase.UserAccount when no explicit cache configured
- Tests verify settings persistence across instances
- Tests demonstrate the fallback priority logic
- Some edge case tests remain challenging due to static state interference

Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>

* Complete fallback test coverage with passing tests

- All new tests pass successfully
- All existing tests continue to pass (18 total)
- Tests validate CacheDatabase fallback when no explicit cache configured
- Tests validate settings persistence across multiple instances
- Removed flaky tests that had static state interference issues

Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>

* Refactor SettingsBase cache lookup to use explicit LINQ filtering (#1149)


Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
Co-authored-by: Glenn <5834289+glennawatson@users.noreply.github.com>
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants