Skip to content

Commit 1cdb8c1

Browse files
authored
improvement(perf): bound trash, file-path and attachment reads (#8945)
* improvement(perf): bound trash, file-path and attachment reads * fix(recently-deleted): cast chat ids in the trash union, keep loaded pages on errors
1 parent bf285f0 commit 1cdb8c1

35 files changed

Lines changed: 1467 additions & 422 deletions
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { listRecentlyDeletedContract } from '@/lib/api/contracts/recently-deleted'
2+
import { cursorRoute, cursorScopeKey } from '@/lib/api/cursor-binding'
3+
import {
4+
defineInternalJsonRoute,
5+
internalOrchestrationErrorPolicy,
6+
internalRateLimits,
7+
internalSessionAuth,
8+
} from '@/lib/api/server/routes'
9+
import {
10+
listRecentlyDeleted,
11+
recentlyDeletedOperations,
12+
} from '@/lib/workspaces/application/list-recently-deleted'
13+
import { readSortedCursor, writeSortedCursor } from '@/app/api/v2/lib/response'
14+
15+
export const dynamic = 'force-dynamic'
16+
17+
function cursorScope(id: string, type: string, search: string | undefined) {
18+
return cursorScopeKey(cursorRoute(listRecentlyDeletedContract, { id }), { type, search })
19+
}
20+
21+
/** GET /api/workspaces/[id]/recently-deleted — One page of the workspace's Recently Deleted view. */
22+
export const GET = defineInternalJsonRoute({
23+
contract: listRecentlyDeletedContract,
24+
auth: internalSessionAuth,
25+
operation: recentlyDeletedOperations.list,
26+
rateLimit: internalRateLimits.none({
27+
reason: 'Replaces the per-type archived lists, which carry no rate limit',
28+
}),
29+
errorPolicy: internalOrchestrationErrorPolicy,
30+
mapInput: ({ params, query }) => ({
31+
workspaceId: params.id,
32+
filter: query.type,
33+
search: query.search,
34+
sortBy: query.sortBy,
35+
sortOrder: query.sortOrder,
36+
limit: query.limit,
37+
cursorKeys: readSortedCursor(
38+
query.cursor,
39+
query.sortBy,
40+
query.sortOrder,
41+
cursorScope(params.id, query.type, query.search)
42+
),
43+
}),
44+
useCase: listRecentlyDeleted,
45+
present: ({ items, nextCursorKeys }, { input }) => ({
46+
items,
47+
nextCursor: writeSortedCursor(
48+
nextCursorKeys,
49+
input.sortBy,
50+
input.sortOrder,
51+
cursorScope(input.workspaceId, input.filter, input.search)
52+
),
53+
}),
54+
})

‎apps/sim/app/workspace/[workspaceId]/components/resource/resource.tsx‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type { BreadcrumbDropConfig } from '@/app/workspace/[workspaceId]/compone
3333
import { ResourceHeader } from '@/app/workspace/[workspaceId]/components/resource/components/resource-header'
3434
import { ResourceOptions } from '@/app/workspace/[workspaceId]/components/resource/components/resource-options'
3535
import { SearchHighlight } from '@/app/workspace/[workspaceId]/components/search-highlight/search-highlight'
36+
import { useLoadMoreSentinel } from '@/hooks/use-load-more-sentinel'
3637

3738
export interface ResourceColumn {
3839
id: string
@@ -287,7 +288,7 @@ const ResourceTable = memo(function ResourceTable({
287288
emptyState,
288289
}: ResourceTableProps) {
289290
const scrollRef = useRef<HTMLDivElement>(null)
290-
const loadMoreRef = useRef<HTMLDivElement>(null)
291+
const loadMoreRef = useLoadMoreSentinel({ onLoadMore, enabled: Boolean(hasMore) })
291292

292293
const showEmptyState = rows.length === 0 && Boolean(emptyState)
293294

@@ -321,20 +322,6 @@ const ResourceTable = memo(function ResourceTable({
321322
}
322323
}, [contextMenuRowId])
323324

324-
useEffect(() => {
325-
if (!onLoadMore || !hasMore) return
326-
const el = loadMoreRef.current
327-
if (!el) return
328-
const observer = new IntersectionObserver(
329-
([entry]) => {
330-
if (entry.isIntersecting) onLoadMore()
331-
},
332-
{ rootMargin: '200px' }
333-
)
334-
observer.observe(el)
335-
return () => observer.disconnect()
336-
}, [onLoadMore, hasMore])
337-
338325
const hasCheckbox = selectable != null
339326
const bodyDrop = rowDragDrop?.body
340327

‎apps/sim/app/workspace/[workspaceId]/settings/components/recently-deleted/query-plan.ts‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)