Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(cloud): retain overview counts during background refresh

Timothy Yin40c491e34deb
diff --git a/apps/cloud/app/composables/useCloudSiteMedia.ts b/apps/cloud/app/composables/useCloudSiteMedia.ts
index 22da6200..cf694339 100644
--- a/apps/cloud/app/composables/useCloudSiteMedia.ts
+++ b/apps/cloud/app/composables/useCloudSiteMedia.ts
@@ -76,7 +76,8 @@ export function useCloudMediaWorkspace(props: {
activeUpload: string | undefined,
activeResumeKey: string | undefined
const canPoll = ref(true)
- const loading = ref(false),
+ const ready = ref(false)
+ const loading = ref(true),
uploadOpen = ref(false)
let reloadGeneration = 0
async function reload() {
@@ -101,6 +102,7 @@ export function useCloudMediaWorkspace(props: {
photos.value = p.photos
jobs.value = p.jobs
albums.value = a.albums
+ ready.value = true
if (!connectionId.value) connectionId.value = s.connections[0]?.id ?? ''
} catch (error) {
if (
@@ -483,6 +485,7 @@ export function useCloudMediaWorkspace(props: {
base,
api,
loading,
+ ready,
uploadOpen,
}
}
diff --git a/apps/cloud/app/pages/sites/[siteId]/overview.vue b/apps/cloud/app/pages/sites/[siteId]/overview.vue
index 0e092791..6766a395 100644
--- a/apps/cloud/app/pages/sites/[siteId]/overview.vue
+++ b/apps/cloud/app/pages/sites/[siteId]/overview.vue
@@ -7,7 +7,7 @@ useSeoMeta({
robots: 'noindex',
})
const site = useEntryContext().value!
-const { photos, albums, jobs, loading } = useCloudSiteMedia()
+const { photos, albums, jobs, loading, ready } = useCloudSiteMedia()
const processingCount = computed(
() =>
jobs.value.filter((job: { state: string }) =>
@@ -27,7 +27,7 @@ const processingCount = computed(
<span class="cf-field-label">{{
$t('cloud.messages.photographs')
}}</span
- ><strong>{{ loading ? '—' : photos.length }}</strong
+ ><strong>{{ ready ? photos.length : '—' }}</strong
><NuxtLink
:to="`/sites/${site.siteId}/photos`"
class="cf-text-link"
@@ -37,7 +37,7 @@ const processingCount = computed(
><CloudCard
><div class="cf-panel-body">
<span class="cf-field-label">{{ $t('cloud.messages.albums') }}</span
- ><strong>{{ loading ? '—' : albums.length }}</strong
+ ><strong>{{ ready ? albums.length : '—' }}</strong
><NuxtLink
:to="`/sites/${site.siteId}/albums`"
class="cf-text-link"
@@ -49,7 +49,7 @@ const processingCount = computed(
<span class="cf-field-label">{{
$t('cloud.messages.processing')
}}</span
- ><strong>{{ loading ? '—' : processingCount }}</strong>
+ ><strong>{{ ready ? processingCount : '—' }}</strong>
<p class="cf-field-hint">
{{
$t(
diff --git a/tests/portal-review-regressions.test.ts b/tests/portal-review-regressions.test.ts
index ec7d155e..cf881372 100644
--- a/tests/portal-review-regressions.test.ts
+++ b/tests/portal-review-regressions.test.ts
@@ -246,3 +246,65 @@ test('public navigation accepts case-preserving photo IDs while rejecting invali
])
assert.equal((await module.default({ path })).statusCode, 404, path)
})
+
+test('Overview data stays unknown before the first response and retains counts during background refresh failures', async () => {
+ let release: (() => void) | undefined
+ let gate = new Promise<void>((resolve) => {
+ release = resolve
+ })
+ let fail = false
+ const module = load(
+ 'apps/cloud/app/composables/useCloudSiteMedia.ts',
+ {
+ useEntryContext: () => ({ value: { scope: 'site:1:user:1', siteId: 1 } }),
+ onMounted: () => {},
+ onBeforeUnmount: () => {},
+ AbortController,
+ crypto,
+ setTimeout,
+ setInterval,
+ clearInterval,
+ $fetch: async (path: string) => {
+ await gate
+ if (fail) throw new Error('Temporary network failure')
+ if (path.endsWith('/photos'))
+ return {
+ photos: [{ id: 'one' }, { id: 'two' }],
+ jobs: [{ state: 'queued' }],
+ }
+ if (path.endsWith('/albums')) return { albums: [{ id: 1 }] }
+ if (path.endsWith('/storage')) return { connections: [] }
+ return { usage: { photos: 2, pending: 1, bytes: 1024 } }
+ },
+ },
+ {
+ '@chronoframe/contracts/storage-diagnostics': {
+ STORAGE_CONNECTION_MESSAGES: {},
+ },
+ },
+ )
+ const media = module.useCloudMediaWorkspace({ siteId: 1, role: 'admin' })
+ assert.equal(media.ready.value, false)
+ assert.equal(media.loading.value, true)
+ const initial = media.reload()
+ release!()
+ await initial
+ assert.equal(media.ready.value, true)
+ assert.equal(media.photos.value.length, 2)
+ assert.equal(media.albums.value.length, 1)
+ gate = new Promise<void>((resolve) => {
+ release = resolve
+ })
+ fail = true
+ const refresh = media.reload()
+ assert.equal(media.loading.value, true)
+ assert.equal(media.ready.value, true)
+ assert.equal(media.photos.value.length, 2)
+ assert.equal(media.jobs.value.length, 1)
+ release!()
+ await refresh
+ assert.equal(media.loading.value, false)
+ assert.equal(media.ready.value, true)
+ assert.equal(media.photos.value.length, 2)
+ assert.equal(media.albums.value.length, 1)
+})