Skip to content

Commit

Permalink
fixup! fix(structure): memoize search query results
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 27, 2024
1 parent 3f252ef commit c3f17de
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
map,
mergeMap,
scan,
share,
shareReplay,
take,
takeUntil,
Expand All @@ -21,7 +22,7 @@ import {
useWorkspace,
} from 'sanity'

import {DEFAULT_ORDERING, PARTIAL_PAGE_LIMIT} from './constants'
import {DEFAULT_ORDERING, FULL_LIST_LIMIT, PARTIAL_PAGE_LIMIT} from './constants'
import {findStaticTypesInFilter, removePublishedWithDrafts} from './helpers'
import {listenSearchQuery} from './listenSearchQuery'
import {type DocumentListPaneItem, type SortOrder} from './types'
Expand Down Expand Up @@ -92,7 +93,7 @@ export function useDocumentList(opts: UseDocumentListOpts): UseDocumentListHookV
}

const partialList$ = listenSearchQuery(listenSearchQueryArgs).pipe(
shareReplay({bufferSize: 1, refCount: true}),
shareReplay({refCount: true, bufferSize: 1}),
)

// we want to fetch the full list if the last result of the partial list is at the limit
Expand All @@ -104,12 +105,12 @@ export function useDocumentList(opts: UseDocumentListOpts): UseDocumentListHookV
mergeMap(() =>
concat(
of({type: 'loadFullList' as const}),
listenSearchQuery({...listenSearchQueryArgs, limit: PARTIAL_PAGE_LIMIT}).pipe(
listenSearchQuery({...listenSearchQueryArgs, limit: FULL_LIST_LIMIT}).pipe(
map((result) => ({type: 'result' as const, result})),
),
),
),
shareReplay({bufferSize: 1, refCount: true}),
share(),
)

// The combined search results from both partial page and full list
Expand Down

0 comments on commit c3f17de

Please sign in to comment.