Skip to content

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.

Backup import: restored photos upload right away

Duarte Santos6905bc23dcf0
diff --git a/frontend/src/lib/media-sync.js b/frontend/src/lib/media-sync.js
index 03ad056f6..016a025d3 100644
--- a/frontend/src/lib/media-sync.js
+++ b/frontend/src/lib/media-sync.js
@@ -105,7 +105,9 @@ export function createMediaSync(deps = {}) {
if (!cfg?.media) { await publishPending({ usage: null }); return }
const files = referencedFiles(st.S)
const refs = files.map(f => f.hash)
- if (!refs.length) { await publishPending({ deferred: 0, rejected: 0, unavailable: 0 }); return }
+ // Nothing referenced (a reset, everything deleted) forgets the last run: the same files coming
+ // back from a backup within ten minutes are new to the server again, not a repeat of that run.
+ if (!refs.length) { lastRun = { refs: '', at: 0, complete: false }; await publishPending({ deferred: 0, rejected: 0, unavailable: 0 }); return }
const key = refs.join(',')
if (!force && lastRun.complete && lastRun.refs === key && d.now() - lastRun.at < DEDUPE_MS) return
if (!force && d.now() < retryNotBefore) return
diff --git a/frontend/src/lib/media-sync.test.js b/frontend/src/lib/media-sync.test.js
index cec131a37..90f6d530f 100644
--- a/frontend/src/lib/media-sync.test.js
+++ b/frontend/src/lib/media-sync.test.js
@@ -137,6 +137,23 @@ describe('syncMedia', () => {
expect(api).toHaveBeenCalledTimes(2)
})
+ it('files that come back after nothing referred to them (reset, then a backup import) go up at once', async () => {
+ const S = { customEx: [{ id: 'a', media: refOf(hex('a')) }] }
+ await put(hex('a'))
+ const store = appStore({ S })
+ const sync = make(store)
+ await sync.syncMedia()
+ expect(api).toHaveBeenCalledTimes(1)
+ store.setState({ S: { customEx: [] } })
+ await sync.syncMedia()
+ clock += 60000
+ store.setState({ S })
+ await put(hex('a'))
+ await sync.syncMedia()
+ expect(api).toHaveBeenCalledTimes(2)
+ expect(apiUpload).toHaveBeenCalledTimes(2)
+ })
+
it('a 429 is honoured for as long as it says', async () => {
const S = { customEx: [{ id: 'a', media: refOf(hex('a')) }] }
await put(hex('a'))
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index 60d909847..36c918602 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -300,6 +300,9 @@ export default function Settings({ page = null, find = null, via = null }) {
await storeBackupMedia(read.files, { limits: limitsFrom(useStore.getState().config) })
}
importBackup(read.state, { mergeWith })
+ // The photos it brought are pending here and maybe gone from the server (a reset): sent now,
+ // not after the ten-minute dedupe of the run before the reset.
+ if (read.files.length) syncMedia({ force: true })
toast(t('Backup imported'))
}
// Signed in, the server is asked first: a workout logged since the backup was made, or on