Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
perf(stats): the Effort card reads each set once, not three times
Duarte Santos8e75ab4d3689
diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsxindex 28df42f73..7c7d29ec1 100644--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@ -381,7 +381,17 @@ function EffortCard({ S }) {() => anchorsByWorkout(S.workouts, opts),[S.workouts, opts],)- const resolve = (s, w, e) => resolveSetRir(s, s, e, w, anchors.get(w), opts)+ // The summary, the weekly curve and the histogram each walk the same sets; a set's reading+ // depends only on the anchors and options, so it is worked out once per set, not three times.+ const resolve = useMemo(() => {+ const seen = new WeakMap()+ return (s, w, e) => {+ if (seen.has(s)) return seen.get(s)+ const r = resolveSetRir(s, s, e, w, anchors.get(w), opts)+ seen.set(s, r)+ return r+ }+ }, [anchors, opts])const sum = effortSummary(S, win, resolve)const weeks = effortWeeks(S, win, resolve)const hist = effortHistogram(S, win, resolve)diff --git a/frontend/src/views/Stats.recovery.test.jsx b/frontend/src/views/Stats.recovery.test.jsxindex 8341ad602..a59e97716 100644--- a/frontend/src/views/Stats.recovery.test.jsx+++ b/frontend/src/views/Stats.recovery.test.jsx@@ -5,7 +5,7 @@ import { Window } from 'happy-dom'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { EXIDX } from '../lib/exercises.js'import { MUSCLES, levelsOf } from '../lib/muscles.js'-import { FATIGUE_STATES, STRENGTH_FLOOR, fatigueHalfLifeOf, FATIGUE_SETS_PER_UNIT } from '../lib/recovery.js'+import { FATIGUE_STATES, STRENGTH_FLOOR, fatigueHalfLifeOf, FATIGUE_SETS_PER_UNIT, resolveSetRir } from '../lib/recovery.js'import { fatigueStateOf } from '../lib/recovery-view.js'import Stats from './Stats.jsx'import Modals from '../components/Modals.jsx'@@ -28,6 +28,12 @@ const mocks = vi.hoisted(() => ({},}))+// Passed through untouched; the spy only counts how often the Effort card reads a set.+vi.mock('../lib/recovery.js', async importOriginal => {+ const actual = await importOriginal()+ return { ...actual, resolveSetRir: vi.fn(actual.resolveSetRir) }+})+vi.mock('../store/useStore.js', () => ({useStore: selector => selector({ S: mocks.S }),}))@@ -381,6 +387,19 @@ describe('Stats estimated effort', () => {expect(container.textContent).toContain('0 rated')})+ // The summary, the weekly curve and the histogram share one reading per set.+ it('reads each set once for the whole card', async () => {+ resetFixture([workout('unrated', BASE_NOW, [+ entry('0025', Array.from({ length: 6 }, () => set(true, { w: 80, r: 8 }))),+ ])])+ resolveSetRir.mockClear()+ await mountStats()+ expect(effortHead().textContent).toContain('estimated')+ const sets = resolveSetRir.mock.calls.map(c => c[0])+ expect(sets.length).toBeGreaterThan(0)+ expect(new Set(sets).size).toBe(sets.length)+ })+it('keeps the logged view badge-free on rated history', async () => {resetFixture([workout('rated', BASE_NOW, [entry('0025', Array.from({ length: 6 }, () => set(true, { w: 80, r: 8, rir: 2 }))),