Skip to content

Commit b28556f

Browse files
committed
Fixes
1 parent 8abb884 commit b28556f

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,22 @@ function ImagePreview({ file }: { file: WorkspaceFileRecord }) {
439439
)
440440
}
441441

442+
const PPTX_CACHE_MAX = 5
443+
442444
const pptxSlideCache = new Map<string, string[]>()
443445

444446
function pptxCacheKey(fileId: string, dataUpdatedAt: number): string {
445447
return `${fileId}:${dataUpdatedAt}`
446448
}
447449

450+
function pptxCacheSet(key: string, slides: string[]): void {
451+
pptxSlideCache.set(key, slides)
452+
if (pptxSlideCache.size > PPTX_CACHE_MAX) {
453+
const oldest = pptxSlideCache.keys().next().value
454+
if (oldest !== undefined) pptxSlideCache.delete(oldest)
455+
}
456+
}
457+
448458
async function renderPptxSlides(
449459
data: Uint8Array,
450460
onSlide: (src: string, index: number) => void,
@@ -453,8 +463,9 @@ async function renderPptxSlides(
453463
const { PPTXViewer } = await import('pptxviewjs')
454464
if (cancelled()) return
455465

456-
const W = 1920
457-
const H = 1080
466+
const dpr = Math.min(window.devicePixelRatio || 1, 2)
467+
const W = Math.round(1920 * dpr)
468+
const H = Math.round(1080 * dpr)
458469

459470
const canvas = document.createElement('canvas')
460471
canvas.width = W
@@ -540,7 +551,7 @@ function PptxPreview({
540551
() => cancelled
541552
)
542553
if (!cancelled && images.length > 0) {
543-
pptxSlideCache.set(cacheKey, images)
554+
pptxCacheSet(cacheKey, images)
544555
}
545556
} catch (err) {
546557
if (!cancelled) {
@@ -557,7 +568,7 @@ function PptxPreview({
557568
return () => {
558569
cancelled = true
559570
}
560-
}, [fileData, dataUpdatedAt, streamingContent, cacheKey, cached])
571+
}, [fileData, dataUpdatedAt, streamingContent, cacheKey])
561572

562573
const error = fetchError
563574
? fetchError instanceof Error

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-registry/resource-registry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const RESOURCE_INVALIDATORS: Record<
129129
},
130130
file: (qc, wId, id) => {
131131
qc.invalidateQueries({ queryKey: workspaceFilesKeys.lists() })
132-
qc.invalidateQueries({ queryKey: workspaceFilesKeys.content(wId, id) })
132+
qc.invalidateQueries({ queryKey: workspaceFilesKeys.contentFile(wId, id) })
133133
qc.invalidateQueries({ queryKey: workspaceFilesKeys.storageInfo() })
134134
},
135135
workflow: (qc, _wId) => {

apps/sim/hooks/queries/workspace-files.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export const workspaceFilesKeys = {
1616
list: (workspaceId: string, scope: WorkspaceFileQueryScope = 'active') =>
1717
[...workspaceFilesKeys.lists(), workspaceId, scope] as const,
1818
contents: () => [...workspaceFilesKeys.all, 'content'] as const,
19+
contentFile: (workspaceId: string, fileId: string) =>
20+
[...workspaceFilesKeys.contents(), workspaceId, fileId] as const,
1921
content: (
2022
workspaceId: string,
2123
fileId: string,
2224
mode: 'text' | 'raw' | 'binary' = 'text'
23-
) => [...workspaceFilesKeys.contents(), workspaceId, fileId, mode] as const,
25+
) => [...workspaceFilesKeys.contentFile(workspaceId, fileId), mode] as const,
2426
storageInfo: () => [...workspaceFilesKeys.all, 'storageInfo'] as const,
2527
}
2628

@@ -122,8 +124,7 @@ export function useWorkspaceFileBinary(workspaceId: string, fileId: string, key:
122124
queryKey: workspaceFilesKeys.content(workspaceId, fileId, 'binary'),
123125
queryFn: ({ signal }) => fetchWorkspaceFileBinary(key, signal),
124126
enabled: !!workspaceId && !!fileId && !!key,
125-
staleTime: 5 * 60 * 1000,
126-
refetchOnWindowFocus: false,
127+
staleTime: 30 * 1000,
127128
})
128129
}
129130

@@ -239,7 +240,7 @@ export function useUpdateWorkspaceFileContent() {
239240
},
240241
onSettled: (_data, _error, variables) => {
241242
queryClient.invalidateQueries({
242-
queryKey: [...workspaceFilesKeys.contents(), variables.workspaceId, variables.fileId],
243+
queryKey: workspaceFilesKeys.contentFile(variables.workspaceId, variables.fileId),
243244
})
244245
queryClient.invalidateQueries({ queryKey: workspaceFilesKeys.lists() })
245246
queryClient.invalidateQueries({ queryKey: workspaceFilesKeys.storageInfo() })
@@ -345,7 +346,7 @@ export function useDeleteWorkspaceFile() {
345346
onSettled: (_data, _error, variables) => {
346347
queryClient.invalidateQueries({ queryKey: workspaceFilesKeys.lists() })
347348
queryClient.removeQueries({
348-
queryKey: workspaceFilesKeys.content(variables.workspaceId, variables.fileId),
349+
queryKey: workspaceFilesKeys.contentFile(variables.workspaceId, variables.fileId),
349350
})
350351
queryClient.invalidateQueries({ queryKey: workspaceFilesKeys.storageInfo() })
351352
},

0 commit comments

Comments
 (0)