Skip to content

Commit 423b34e

Browse files
✨ Add caching strategy and double debounce time #1987 (#2080)
1 parent e73323e commit 423b34e

File tree

6 files changed

+47
-5
lines changed

6 files changed

+47
-5
lines changed

web/lib/algolia.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import algoliasearch, { AlgoliaSearchOptions } from 'algoliasearch/lite'
22
import { algolia } from './config'
3+
import { createInMemoryCache } from '@algolia/cache-in-memory'
4+
import { createFallbackableCache } from '@algolia/cache-common'
5+
import { createBrowserLocalStorageCache } from '@algolia/cache-browser-local-storage'
36

4-
export const searchClient = (options: AlgoliaSearchOptions | undefined) =>
5-
algoliasearch(algolia.applicationId, algolia.searchApiKey, options)
7+
export const searchClient = (options?: AlgoliaSearchOptions) =>
8+
algoliasearch(algolia.applicationId, algolia.searchApiKey, {
9+
...options,
10+
responsesCache: createFallbackableCache({
11+
caches: [
12+
createBrowserLocalStorageCache({
13+
key: `algolia-responses-${algolia.applicationId}`,
14+
timeToLive: 600, // 10 minutes cache
15+
}),
16+
createInMemoryCache(),
17+
],
18+
}),
19+
})

web/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"type-check": "tsc --project tsconfig.json --pretty --noEmit"
2222
},
2323
"dependencies": {
24+
"@algolia/cache-browser-local-storage": "^4.22.1",
25+
"@algolia/cache-common": "^4.22.1",
26+
"@algolia/cache-in-memory": "^4.22.1",
2427
"@chakra-ui/react": "^2.4.2",
2528
"@chakra-ui/skip-nav": "^2.0.12",
2629
"@emotion/react": "^11",

web/pageComponents/pageTemplates/newsroom/UncontrolledSearchBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const Input = styled.input`
4242

4343
export type SearchBoxProps = UseSearchBoxProps
4444

45-
const DEBOUNCE_TIME = 300
45+
const DEBOUNCE_TIME = 800
4646
let timerId: any = undefined
4747

4848
const queryHook: UseSearchBoxProps['queryHook'] = (query, search) => {

web/pageComponents/search/Search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const StyledPagination = styled(Pagination)`
2222
margin-top: var(--space-xLarge);
2323
justify-content: center;
2424
`
25-
const searchClient = client(undefined)
25+
const searchClient = client()
2626
const queriedSearchClient: SearchClient = {
2727
...searchClient,
2828
search(requests: any) {

web/pageComponents/search/SearchBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useSearchBox, UseSearchBoxProps } from 'react-instantsearch'
33
import ControlledSearchBox from './ControlledSearchBox'
44
import { SearchContext } from './SearchContext'
55

6-
const DEBOUNCE_TIME = 300
6+
const DEBOUNCE_TIME = 800
77

88
export type SearchBoxProps = ComponentProps<'div'> & UseSearchBoxProps
99

web/pnpm-lock.yaml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)