Skip to content

Commit 5e9528b

Browse files
refactor: optimize cache and retry handling
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent ff198f4 commit 5e9528b

14 files changed

Lines changed: 255 additions & 130 deletions

File tree

.flow/epics/fn-17-vfs.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"branch_name": "fn-17-optimization",
3+
"created_at": "2026-01-30T12:12:35.947254Z",
4+
"depends_on_epics": [],
5+
"id": "fn-17-vfs",
6+
"next_task": 1,
7+
"plan_review_status": "unknown",
8+
"plan_reviewed_at": null,
9+
"spec_path": ".flow/specs/fn-17-vfs.md",
10+
"status": "open",
11+
"title": "Optimization cleanup from full scan",
12+
"updated_at": "2026-01-30T12:12:35.947723Z"
13+
}

.flow/specs/fn-17-vfs.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# fn-17-vfs Optimization cleanup from full scan
2+
3+
## Overview
4+
Implement prioritized improvements from the full scan (cache correctness, retry consistency, cache hygiene, and OCR efficiency).
5+
6+
## Scope
7+
- WeatherService cache invalidation tied to user location changes
8+
- GeminiService retry unification with RetryPolicy/withRetry
9+
- MatchCache expiration cleanup and cacheExpiration usage
10+
- IngredientOCR CIContext reuse
11+
12+
## Approach
13+
1) Track last weather location + invalidate cache on significant location change.
14+
2) Route GeminiService network calls through withRetry to align with RetryPolicy and Retry-After.
15+
3) Align MatchCache expiration checks with cacheExpiration and clean expired entries consistently.
16+
4) Reuse CIContext for OCR preprocessing.
17+
18+
## Quick commands
19+
<!-- Required: at least one smoke command for the repo -->
20+
- `make test`
21+
22+
## Acceptance
23+
- [ ] Weather cache invalidation respects location changes
24+
- [ ] GeminiService retry uses RetryPolicy/withRetry
25+
- [ ] MatchCache expiration cleanup is consistent
26+
- [ ] OCR preprocessing reuses CIContext
27+
- [ ] Tests/linters pass
28+
29+
## References
30+
- SkinLab/Core/Network/WeatherService.swift
31+
- SkinLab/Core/Network/GeminiService.swift
32+
- SkinLab/Core/Network/RetryPolicy.swift
33+
- SkinLab/Features/Community/Services/MatchCache.swift
34+
- SkinLab/Core/Utils/IngredientOCR.swift

.flow/tasks/fn-17-vfs.1.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"assignee": null,
3+
"claim_note": "",
4+
"claimed_at": null,
5+
"created_at": "2026-01-30T12:14:28.042624Z",
6+
"depends_on": [],
7+
"epic": "fn-17-vfs",
8+
"id": "fn-17-vfs.1",
9+
"priority": null,
10+
"spec_path": ".flow/tasks/fn-17-vfs.1.md",
11+
"status": "todo",
12+
"title": "Weather cache invalidation by location",
13+
"updated_at": "2026-01-30T12:14:52.218140Z"
14+
}

.flow/tasks/fn-17-vfs.1.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fn-17-vfs.1 Weather cache invalidation by location
2+
3+
## Description
4+
Update WeatherService caching so location changes invalidate cached weather. Track last fetch location and clear cache when distance exceeds threshold or location is unavailable.
5+
## Acceptance
6+
- Cache invalidates on significant location change
7+
- Existing weather cache still used when location stable and cache fresh
8+
- Tests/linters pass
9+
## Done summary
10+
- add location-aware cache invalidation in WeatherService
11+
- fetch location before serving cache and clear when distance exceeds threshold
12+
## Evidence
13+
- Commits:
14+
- Tests:
15+
- PRs:

.flow/tasks/fn-17-vfs.2.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"assignee": null,
3+
"claim_note": "",
4+
"claimed_at": null,
5+
"created_at": "2026-01-30T12:14:30.898057Z",
6+
"depends_on": [],
7+
"epic": "fn-17-vfs",
8+
"id": "fn-17-vfs.2",
9+
"priority": null,
10+
"spec_path": ".flow/tasks/fn-17-vfs.2.md",
11+
"status": "todo",
12+
"title": "Unify GeminiService retry policy",
13+
"updated_at": "2026-01-30T12:15:01.584732Z"
14+
}

.flow/tasks/fn-17-vfs.2.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fn-17-vfs.2 Unify GeminiService retry policy
2+
3+
## Description
4+
Refactor GeminiService to use the shared RetryPolicy/withRetry utilities, including honoring Retry-After when present, to align with global retry limits.
5+
## Acceptance
6+
- GeminiService uses withRetry/RetryPolicy for network calls
7+
- Retry-After is respected when available
8+
- Tests/linters pass
9+
## Done summary
10+
- refactor GeminiService analysis and ingredient requests to use withRetry
11+
- centralize response validation and error mapping with Retry-After support
12+
## Evidence
13+
- Commits:
14+
- Tests:
15+
- PRs:

.flow/tasks/fn-17-vfs.3.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"assignee": null,
3+
"claim_note": "",
4+
"claimed_at": null,
5+
"created_at": "2026-01-30T12:14:33.495635Z",
6+
"depends_on": [],
7+
"epic": "fn-17-vfs",
8+
"id": "fn-17-vfs.3",
9+
"priority": null,
10+
"spec_path": ".flow/tasks/fn-17-vfs.3.md",
11+
"status": "todo",
12+
"title": "MatchCache expiration cleanup",
13+
"updated_at": "2026-01-30T12:15:09.264002Z"
14+
}

.flow/tasks/fn-17-vfs.3.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fn-17-vfs.3 MatchCache expiration cleanup
2+
3+
## Description
4+
Make MatchCache expiration behavior consistent: use cacheExpiration constant in isExpired checks and remove expired entries when accessed.
5+
## Acceptance
6+
- cacheExpiration constant is used consistently
7+
- Expired entries are invalidated on read paths
8+
- Tests/linters pass
9+
## Done summary
10+
- align MatchCache expiration checks with cacheExpiration constant
11+
- invalidate expired entries in recommendation and entry accessors
12+
## Evidence
13+
- Commits:
14+
- Tests:
15+
- PRs:

.flow/tasks/fn-17-vfs.4.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"assignee": null,
3+
"claim_note": "",
4+
"claimed_at": null,
5+
"created_at": "2026-01-30T12:14:36.516188Z",
6+
"depends_on": [],
7+
"epic": "fn-17-vfs",
8+
"id": "fn-17-vfs.4",
9+
"priority": null,
10+
"spec_path": ".flow/tasks/fn-17-vfs.4.md",
11+
"status": "todo",
12+
"title": "Reuse CIContext in IngredientOCR",
13+
"updated_at": "2026-01-30T12:15:15.463784Z"
14+
}

.flow/tasks/fn-17-vfs.4.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# fn-17-vfs.4 Reuse CIContext in IngredientOCR
2+
3+
## Description
4+
Reuse a shared CIContext in IngredientOCR preprocessing to avoid repeated context creation overhead.
5+
## Acceptance
6+
- IngredientOCR uses shared CIContext
7+
- Behavior unchanged for preprocessing output
8+
- Tests/linters pass
9+
## Done summary
10+
- reuse a shared CIContext inside IngredientOCRService preprocessing
11+
## Evidence
12+
- Commits:
13+
- Tests:
14+
- PRs:

0 commit comments

Comments
 (0)