Skip to content

Refactor utility/model hot paths into leaner drop-in implementations#140

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-for-performance-optimizations
Closed

Refactor utility/model hot paths into leaner drop-in implementations#140
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-for-performance-optimizations

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

This Pull Request tightens core utility/model paths with behavior-preserving refactors focused on lower allocation, less duplication, and simpler control flow. It keeps the public surface and expected runtime behavior intact while reducing maintenance and execution overhead.

  • Scope

    • Narrow refactor only in shared helpers used across routing, deep-link parsing, and analytics unit adaptation.
  • Key changes

    • Consolidated duplicated DB URL resolution into one internal helper (configured_exercise_db_url) used by both DB and image base URL accessors.
    • Reused a single CSV ID parser for deep-link session-start flows instead of duplicated split/filter/map blocks.
    • Optimized query percent-decoding to avoid allocation when + is absent (borrowed fast path via Cow).
    • Switched signed time formatting to unsigned_abs() for safer/intention-revealing negative handling.
    • Simplified exercise-type tag selection with a compact match on category/force semantics.
    • Kept explicit empty-input handling for analytics average computation to preserve semantic clarity.
  • Example

fn percent_decode(s: &str) -> String {
    use std::borrow::Cow;
    let s = if s.contains('+') {
        Cow::Owned(s.replace('+', "%20"))
    } else {
        Cow::Borrowed(s)
    };
    percent_encoding::percent_decode_str(&s)
        .decode_utf8_lossy()
        .into_owned()
}

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

Copilot AI and others added 2 commits April 15, 2026 22:15
@github-actions
Copy link
Copy Markdown

📊 Coverage Report

Lines: 3756/4996 (75.18014411529224%)

⏱️ Tests: 255 tests in 0.607s

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)

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