mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(ui): read nested stats from stats_update events
The server sends stats_update as {stats, timestamp}, but the realtime store read the counters from the top level of the payload. About 30 seconds after load, the first broadcast replaced the polled stats with undefined values, and the dashboard tiles showed 0. The store now unwraps the nested stats object.
This commit is contained in:
@@ -53,6 +53,22 @@ describe('useRealtimeStore', () => {
|
||||
expect(store.lastStats).toMatchObject({ total_packages: 42, total_size: 1024 })
|
||||
})
|
||||
|
||||
it('unwraps the server stats_update shape {stats, timestamp}', () => {
|
||||
const store = useRealtimeStore()
|
||||
store.ingest(
|
||||
makeEvent('stats_update', {
|
||||
stats: { total_packages: 1454, total_size: 980870617, total_downloads: 5376, scanned_packages: 1451 },
|
||||
timestamp: '2026-11-23T16:00:00Z',
|
||||
}),
|
||||
)
|
||||
expect(store.lastStats).toMatchObject({
|
||||
total_packages: 1454,
|
||||
total_size: 980870617,
|
||||
total_downloads: 5376,
|
||||
scanned_packages: 1451,
|
||||
})
|
||||
})
|
||||
|
||||
it('exposes filtered computed slices', () => {
|
||||
const store = useRealtimeStore()
|
||||
store.ingest(makeEvent('package_cached'))
|
||||
|
||||
@@ -55,7 +55,9 @@ export const useRealtimeStore = defineStore('realtime', () => {
|
||||
events.value.splice(0, events.value.length - EVENTS_CAP)
|
||||
}
|
||||
if (event.type === 'stats_update') {
|
||||
lastStats.value = event.payload as RealtimeStats
|
||||
// The server nests the counters under `stats`; reading the payload flat shows zeros.
|
||||
const nested = event.payload.stats
|
||||
lastStats.value = (nested && typeof nested === 'object' ? nested : event.payload) as RealtimeStats
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user