fix(web): [OCISDEV-1511] refresh files stuck in processing after upload or copy (#13134)

* fix(web): [OCISDEV-1511] refresh files stuck in processing after upload or copy

A postprocessing-finished event that arrives while a folder reload or a
fetch after copy is still in flight is dropped, because the resource is
not in the store yet. The response then adds the resource as processing
and nothing clears it until a page reload.

Remember finished items for a short time and refetch them when they show
up in the store as processing.

* chore: [OCISDEV-1511] add changelog
This commit is contained in:
Matteo authored and GitHub committed 2026-10-13 12:22:01 +02:00
1 parent 037ac76d26
commit 6c8fe4ebf7
7 files changed
+170 -3

No files matched your search

@@ -0,0 +1,11 @@
Bugfix: Files no longer stay in processing after upload or copy
After uploading or copying files, some of them sometimes stayed greyed out as
"processing" until the page was reloaded. This happened when processing
finished while the file list was still being loaded: the update from the
server was ignored and the list then showed the file as still processing.
Files whose processing has finished are now refreshed automatically when they
show up in the file list as processing.
https://github.com/owncloud/ocis/pull/13134
@@ -74,6 +74,8 @@ import {
sseEventWrapper,
onSSELinkUpdatedEvent,
onSSEBackchannelLogoutEvent,
ProcessedItems,
refreshStaleProcessingResources,
SseEventWrapperOptions
} from './sse'
import { loadAppTranslations } from '../helpers/language'
@@ -762,6 +764,22 @@ export const registerSSEEventListeners = ({
}
)
const processedItems: ProcessedItems = new Map()
resourcesStore.$onAction(({ name, after }) => {
if (!['initResourceList', 'setResources', 'upsertResource', 'upsertResources'].includes(name)) {
return
}
after(() =>
refreshStaleProcessingResources({
resourcesStore,
spacesStore,
clientService,
processedItems
})
)
})
const sseEventWrapperOptions = {
resourcesStore,
spacesStore,
@@ -773,7 +791,8 @@ export const registerSSEEventListeners = ({
previewService,
language,
router,
resourceQueue
resourceQueue,
processedItems
} satisfies Partial<SseEventWrapperOptions>
clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_RENAMED, (msg) =>
@@ -74,7 +74,8 @@ export const onSSEProcessingFinishedEvent = async ({
spacesStore,
clientService,
resourceQueue,
previewService
previewService,
processedItems
}: SSEEventOptions) => {
if (!isItemInCurrentFolder({ resourcesStore, parentFolderId: sseData.parentitemid })) {
return false
@@ -85,6 +86,12 @@ export const onSSEProcessingFinishedEvent = async ({
return
}
/**
* A request that was sent before processing finished can still land after this event and
* add the resource as processing, see refreshStaleProcessingResources.
*/
processedItems.set(sseData.itemid, { spaceId: space.id, finishedAt: Date.now() })
/**
* If resource is not loaded, it suggests an upload is in progress.
*/
@@ -142,6 +149,55 @@ export const onSSEProcessingFinishedEvent = async ({
}
}
const PROCESSED_ITEM_TTL = 60_000
/**
* Refetches resources that are marked as processing in the store although their
* postprocessing-finished event has already been received. This happens when a request
* (e.g. the folder reload after an upload) was answered while processing was still running
* but only landed in the store after the event had been handled.
*/
export const refreshStaleProcessingResources = async ({
resourcesStore,
spacesStore,
clientService,
processedItems
}: Pick<
SSEEventOptions,
'resourcesStore' | 'spacesStore' | 'clientService' | 'processedItems'
>) => {
const requests: Promise<void>[] = []
for (const [id, { spaceId, finishedAt }] of processedItems) {
if (Date.now() - finishedAt > PROCESSED_ITEM_TTL) {
processedItems.delete(id)
continue
}
const resource = resourcesStore.resources.find((r) => r.id === id)
const space = spacesStore.spaces.find((s) => s.id === spaceId)
if (!resource?.processing || !space) {
continue
}
processedItems.delete(id)
requests.push(
(async () => {
const updatedResource = await clientService.webdav.getFileInfo(space, {
path: '',
fileId: id
})
// check again in case the user has navigated away in the meantime
if (resourcesStore.resources.some((r) => r.id === id)) {
resourcesStore.upsertResource(updatedResource)
}
})()
)
}
await Promise.allSettled(requests)
}
export const onSSEItemTrashedEvent = ({
sseData,
language,
@@ -24,6 +24,11 @@ export const eventSchema = z.object({
export type EventSchemaType = z.infer<typeof eventSchema>
/**
* Items whose postprocessing has finished, keyed by item id.
*/
export type ProcessedItems = Map<string, { spaceId: string; finishedAt: number }>
export interface SSEEventOptions {
resourcesStore: ResourcesStore
spacesStore: SpacesStore
@@ -36,6 +41,7 @@ export interface SSEEventOptions {
router: Router
language: Language
resourceQueue: PQueue
processedItems: ProcessedItems
sseData: EventSchemaType
}
@@ -16,7 +16,10 @@ import {
onSSEItemMovedEvent,
onSSEItemRenamedEvent,
onSSEItemRestoredEvent,
onSSEItemTrashedEvent
onSSEItemTrashedEvent,
onSSEProcessingFinishedEvent,
ProcessedItems,
refreshStaleProcessingResources
} from '../../../../src/container/sse'
import { Router } from 'vue-router'
import { mock, mockDeep } from 'vitest-mock-extended'
@@ -422,6 +425,74 @@ describe('file events', () => {
expect(mocks.resourcesStore.upsertResource).not.toHaveBeenCalled()
})
})
describe('onSSEProcessingFinishedEvent', () => {
it('remembers the item when the event arrives before the resource is loaded', async () => {
const mocks = getMocks()
const sseData = mock<EventSchemaType>({
itemid: 'file1',
spaceid: 'space1',
parentitemid: 'currenFolder!currentFolder',
initiatorid: 'local1'
})
await onSSEProcessingFinishedEvent({ sseData, ...mocks })
expect(mocks.processedItems.get('file1')).toEqual(
expect.objectContaining({ spaceId: 'space1' })
)
expect(mocks.clientService.webdav.listFiles).not.toHaveBeenCalled()
})
it('does not remember the item when it is not in the current folder', async () => {
const mocks = getMocks()
const sseData = mock<EventSchemaType>({
itemid: 'file1',
spaceid: 'space1',
parentitemid: 'otherFolder!otherFolder',
initiatorid: 'local1'
})
await onSSEProcessingFinishedEvent({ sseData, ...mocks })
expect(mocks.processedItems.size).toBe(0)
})
})
describe('refreshStaleProcessingResources', () => {
it('refetches a resource that got loaded as processing after its processing had finished', async () => {
const staleResource = mock<Resource>({ id: 'file1', storageId: 'space1', processing: true })
const mocks = getMocks({ resources: [staleResource] })
const updatedResource = mock<Resource>({ id: 'file1', processing: false })
mocks.clientService.webdav.getFileInfo.mockResolvedValue(updatedResource)
mocks.processedItems.set('file1', { spaceId: 'space1', finishedAt: Date.now() })
await refreshStaleProcessingResources(mocks)
expect(mocks.clientService.webdav.getFileInfo).toHaveBeenCalledWith(
mocks.spacesStore.spaces[0],
{
path: '',
fileId: 'file1'
}
)
expect(mocks.resourcesStore.upsertResource).toHaveBeenCalledWith(updatedResource)
expect(mocks.processedItems.has('file1')).toBe(false)
})
it('does nothing when the resource is not processing', async () => {
const resource = mock<Resource>({ id: 'file1', storageId: 'space1', processing: false })
const mocks = getMocks({ resources: [resource] })
mocks.processedItems.set('file1', { spaceId: 'space1', finishedAt: Date.now() })
await refreshStaleProcessingResources(mocks)
expect(mocks.clientService.webdav.getFileInfo).not.toHaveBeenCalled()
expect(mocks.processedItems.has('file1')).toBe(true)
})
it('drops expired items without refetching', async () => {
const staleResource = mock<Resource>({ id: 'file1', storageId: 'space1', processing: true })
const mocks = getMocks({ resources: [staleResource] })
mocks.processedItems.set('file1', { spaceId: 'space1', finishedAt: Date.now() - 120_000 })
await refreshStaleProcessingResources(mocks)
expect(mocks.clientService.webdav.getFileInfo).not.toHaveBeenCalled()
expect(mocks.processedItems.has('file1')).toBe(false)
})
})
})
const getMocks = ({
currentFolder = mockDeep<Resource>({
@@ -449,8 +520,10 @@ const getMocks = ({
$gettext: vi.fn((m) => m)
})
const resourceQueue = mockDeep<PQueue>()
const processedItems: ProcessedItems = new Map()
return {
processedItems,
resourcesStore,
spacesStore,
router,
@@ -129,6 +129,7 @@ const getMocks = ({
clientService,
previewService,
resourceQueue,
processedItems: new Map(),
language
}
}
@@ -736,6 +736,7 @@ const getMocks = ({
clientService,
previewService,
resourceQueue,
processedItems: new Map(),
language
}
}