Skip to content

Copilot/refactor for performance optimizations#141

Merged
gfauredev merged 3 commits intomainfrom
copilot/refactor-for-performance-optimizations
Apr 17, 2026
Merged

Copilot/refactor for performance optimizations#141
gfauredev merged 3 commits intomainfrom
copilot/refactor-for-performance-optimizations

Conversation

@gfauredev
Copy link
Copy Markdown
Owner

@gfauredev gfauredev commented Apr 17, 2026

This Pull Request…

Engineering Principles

  • PR only contains changes strictly related to the requested feature or fix,
    scope is focused (no unrelated dependency updates or formatting)
  • This code totally respects README’s Engineering Principles

CI/CD Readiness

  • Branch follows Conventional Branch: feat/…, fix/…, refactor/…, …
  • Code is formatted with dx fmt; cargo fmt
  • All checks pass, nix flake checks succeeds without warnings
    • Code compiles, dx build with necessary platform flags succeeds
    • cargo clippy -- -D warnings -W clippy::all -W clippy::pedantic
      produces zero warnings
    • All unit tests pass without warnings
      cargo llvm-cov nextest --ignore-filename-regex '(src/components/|\.cargo/registry/|nix/store)'
    • End-to-end tests pass maestro test --headless maestro/web
      maestro test --headless maestro/android

Summary by CodeRabbit

  • Refactor
    • Internal optimisations across analytics, model and utility code for more consistent behaviour and slight runtime improvements.
    • Centralised configuration retrieval for exercise resources and unified CSV ID parsing to reduce duplication.
    • Improved time/tag mapping logic for clearer internal flow.
    • More efficient string handling to avoid unnecessary allocations.

Copilot AI and others added 2 commits April 15, 2026 22:15
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0627fcc0-dbce-42e7-924c-4279de733bc0

📥 Commits

Reviewing files that changed from the base of the PR and between 061cfb7 and 575f0be.

📒 Files selected for processing (1)
  • src/utils.rs

📝 Walkthrough

Walkthrough

Consolidated URL resolution and CSV parsing in utilities, optimised percent-decoding allocations, and small refactors in models: inlined average computation and replaced conditional logic with a match for exercise tagging. No public signatures were changed.

Changes

Cohort / File(s) Summary
Model tweaks
src/models/analytics.rs, src/models/mod.rs
Inlined average computation in adapt_metric_unit; switched conditional if/else to a match in exercise_type_tag and changed negative-seconds unsigned conversion in format_time_i64. No behavioural changes to outputs.
Utility consolidation & optimisation
src/utils.rs
Added configured_exercise_db_url() and delegated get_exercise_db_url() / get_exercise_images_base_url() to it; introduced parse_csv_ids() and replaced duplicated CSV parsing; added #[must_use] to parse_web_deep_link_query; optimised percent_decode to avoid allocations when possible.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I nibble at strings and hop through the code,
I gather loose URLs and tidy the road.
CSV crumbs swept, percent signs light,
A cleaner trail for the next sprint flight. ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is a template with all checklist items unchecked and no actual context about the changes, failing to explain the engineering rationale or implementation details. Complete the checklist items with actual status, and add a summary section explaining what was refactored and why, along with any performance improvements achieved.
Title check ❓ Inconclusive The title 'Copilot/refactor for performance optimizations' is vague and generic, using non-descriptive terms that don't convey meaningful information about the specific changes made. Provide a more specific title that describes the primary change, such as 'Refactor utility parsing and metric calculations' or 'Optimise URL lookup and CSV parsing logic'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ 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 copilot/refactor-for-performance-optimizations

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

@github-actions
Copy link
Copy Markdown

📊 Coverage Report

Lines: 3756/4996 (75.18014411529224%)

⏱️ Tests: 255 tests in 0.476s

FilenameFunction CoverageLine CoverageRegion CoverageBranch Coverage
main.rs
  22.00% (11/50)
  58.94% (155/263)
  60.56% (218/360)
- (0/0)
models/analytics.rs
   0.00% (0/6)
   0.00% (0/33)
   0.00% (0/45)
- (0/0)
models/enums.rs
 100.00% (28/28)
 100.00% (147/147)
 100.00% (337/337)
- (0/0)
models/exercise.rs
  92.00% (46/50)
  92.10% (548/595)
  91.01% (749/823)
- (0/0)
models/log.rs
 100.00% (12/12)
 100.00% (118/118)
 100.00% (144/144)
- (0/0)
models/mod.rs
 100.00% (11/11)
 100.00% (67/67)
 100.00% (97/97)
- (0/0)
models/session.rs
  72.22% (13/18)
  84.36% (151/179)
  83.33% (210/252)
- (0/0)
models/units.rs
 100.00% (28/28)
 100.00% (167/167)
  98.88% (353/357)
- (0/0)
services/app_state.rs
   1.89% (1/53)
   2.54% (11/433)
   2.32% (15/646)
- (0/0)
services/exercise_db.rs
  88.81% (127/143)
  90.30% (1210/1340)
  89.61% (1924/2147)
- (0/0)
services/exercise_loader.rs
   0.00% (0/14)
   0.00% (0/100)
   0.00% (0/135)
- (0/0)
services/native_queue.rs
   0.00% (0/15)
   0.00% (0/145)
   0.00% (0/197)
- (0/0)
services/notifications.rs
   0.00% (0/3)
   0.00% (0/9)
   0.00% (0/10)
- (0/0)
services/service_worker.rs
 100.00% (2/2)
 100.00% (6/6)
 100.00% (6/6)
- (0/0)
services/storage.rs
  63.77% (88/138)
  80.97% (766/946)
  83.53% (1187/1421)
- (0/0)
services/wake_lock.rs
 100.00% (2/2)
 100.00% (5/5)
 100.00% (5/5)
- (0/0)
utils.rs
  91.36% (74/81)
  91.42% (405/443)
  91.78% (648/706)
- (0/0)
Totals
  67.74% (443/654)
  75.18% (3756/4996)
  76.65% (5893/7688)
- (0/0)

Copy link
Copy Markdown
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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils.rs`:
- Around line 59-60: configured_exercise_db_url() currently only rejects empty
strings and may return whitespace-only or unnormalised values; update it to trim
the input (and re-check emptiness) before returning Some so callers never get
whitespace-only URLs, and apply the same trimming/emptiness check to the other
configured_* URL helpers referenced (the other functions around lines 69-70 and
73-85) so all URL single-source-of-truth helpers normalize input consistently
instead of returning raw untrimmed strings.
- Around line 250-255: The parse_csv_ids function currently preserves
surrounding whitespace which leads to IDs like " Barbell_Squat" failing
downstream; update parse_csv_ids to trim each split token (use id.trim()) before
converting to String and ensure you filter out empty strings after trimming, and
confirm callers such as StartSession consume the returned trimmed IDs so stored
IDs have no leading/trailing spaces.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d473e091-8320-498b-bea4-704e79026a51

📥 Commits

Reviewing files that changed from the base of the PR and between b209626 and 061cfb7.

📒 Files selected for processing (3)
  • src/models/analytics.rs
  • src/models/mod.rs
  • src/utils.rs

Comment thread src/utils.rs
Comment on lines +59 to 60
configured_exercise_db_url().unwrap_or_else(|| EXERCISE_DB_BASE_URL.to_string())
}
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.

⚠️ Potential issue | 🟠 Major

Harden configured URL sanitisation at the single source of truth.

configured_exercise_db_url() only filters is_empty(), so whitespace-only or unnormalised values can be treated as valid and then break both DB and image base URL consumers. Normalise (or at least trim) before returning Some.

💡 Proposed fix
 fn configured_exercise_db_url() -> Option<String> {
     #[cfg(target_arch = "wasm32")]
     {
         web_sys::window()
             .and_then(|window| window.local_storage().ok().flatten())
             .and_then(|storage| storage.get_item(EXERCISE_DB_URL_STORAGE_KEY).ok().flatten())
-            .filter(|url| !url.is_empty())
+            .and_then(|url| {
+                let normalized = normalize_db_url(&url);
+                (!normalized.is_empty()).then_some(normalized)
+            })
     }
     #[cfg(not(target_arch = "wasm32"))]
     {
         use crate::services::storage::native_storage;
-        native_storage::get_config_value(EXERCISE_DB_URL_STORAGE_KEY).filter(|url| !url.is_empty())
+        native_storage::get_config_value(EXERCISE_DB_URL_STORAGE_KEY).and_then(|url| {
+            let normalized = normalize_db_url(&url);
+            (!normalized.is_empty()).then_some(normalized)
+        })
     }
 }

Also applies to: 69-70, 73-85

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils.rs` around lines 59 - 60, configured_exercise_db_url() currently
only rejects empty strings and may return whitespace-only or unnormalised
values; update it to trim the input (and re-check emptiness) before returning
Some so callers never get whitespace-only URLs, and apply the same
trimming/emptiness check to the other configured_* URL helpers referenced (the
other functions around lines 69-70 and 73-85) so all URL single-source-of-truth
helpers normalize input consistently instead of returning raw untrimmed strings.

Comment thread src/utils.rs
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@gfauredev gfauredev merged commit 9d6c482 into main Apr 17, 2026
4 of 5 checks passed
@gfauredev gfauredev deleted the copilot/refactor-for-performance-optimizations branch April 17, 2026 21:38
@github-actions
Copy link
Copy Markdown

📊 Coverage Report

Lines: 3757/4997 (75.18511106663999%)

⏱️ Tests: 255 tests in 0.538s

FilenameFunction CoverageLine CoverageRegion CoverageBranch Coverage
main.rs
  22.00% (11/50)
  58.94% (155/263)
  60.56% (218/360)
- (0/0)
models/analytics.rs
   0.00% (0/6)
   0.00% (0/33)
   0.00% (0/45)
- (0/0)
models/enums.rs
 100.00% (28/28)
 100.00% (147/147)
 100.00% (337/337)
- (0/0)
models/exercise.rs
  92.00% (46/50)
  92.10% (548/595)
  91.01% (749/823)
- (0/0)
models/log.rs
 100.00% (12/12)
 100.00% (118/118)
 100.00% (144/144)
- (0/0)
models/mod.rs
 100.00% (11/11)
 100.00% (67/67)
 100.00% (97/97)
- (0/0)
models/session.rs
  72.22% (13/18)
  84.36% (151/179)
  83.33% (210/252)
- (0/0)
models/units.rs
 100.00% (28/28)
 100.00% (167/167)
  98.88% (353/357)
- (0/0)
services/app_state.rs
   1.89% (1/53)
   2.54% (11/433)
   2.32% (15/646)
- (0/0)
services/exercise_db.rs
  88.81% (127/143)
  90.30% (1210/1340)
  89.61% (1924/2147)
- (0/0)
services/exercise_loader.rs
   0.00% (0/14)
   0.00% (0/100)
   0.00% (0/135)
- (0/0)
services/native_queue.rs
   0.00% (0/15)
   0.00% (0/145)
   0.00% (0/197)
- (0/0)
services/notifications.rs
   0.00% (0/3)
   0.00% (0/9)
   0.00% (0/10)
- (0/0)
services/service_worker.rs
 100.00% (2/2)
 100.00% (6/6)
 100.00% (6/6)
- (0/0)
services/storage.rs
  63.77% (88/138)
  80.97% (766/946)
  83.53% (1187/1421)
- (0/0)
services/wake_lock.rs
 100.00% (2/2)
 100.00% (5/5)
 100.00% (5/5)
- (0/0)
utils.rs
  91.36% (74/81)
  91.44% (406/444)
  91.80% (649/707)
- (0/0)
Totals
  67.74% (443/654)
  75.19% (3757/4997)
  76.65% (5894/7689)
- (0/0)

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.

2 participants