Skip to content

Commit

Permalink
feat: use different cache key for command bar (#7530)
Browse files Browse the repository at this point in the history
Now command bar and search do not share same cache, so they wont
conflict anymore.
  • Loading branch information
sjaanus authored Jul 3, 2024
1 parent d924519 commit fc95d45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const CommandSearchFeatures = ({
{
revalidateOnFocus: false,
},
'command-bar-cache',
);

const flags: CommandResultGroupItem[] = features.map((feature) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const fallbackData: SearchFeaturesSchema = {
};

const SWR_CACHE_SIZE = 10;
const PREFIX_KEY = 'api/admin/search/features?';
const PATH = 'api/admin/search/features?';

const createFeatureSearch = () => {
const internalCache: InternalCache = {};
Expand Down Expand Up @@ -55,17 +55,19 @@ const createFeatureSearch = () => {
return (
params: SearchFeaturesParams,
options: SWRConfiguration = {},
cachePrefix: string = '',
): UseFeatureSearchOutput => {
const { KEY, fetcher } = getFeatureSearchFetcher(params);
const swrKey = `${cachePrefix}${KEY}`;
const cacheId = params.project || '';
useClearSWRCache(KEY, PREFIX_KEY, SWR_CACHE_SIZE);
useClearSWRCache(swrKey, PATH, SWR_CACHE_SIZE);

useEffect(() => {
initCache(params.project || '');
}, []);

const { data, error, mutate, isLoading } = useSWR<SearchFeaturesSchema>(
KEY,
swrKey,
fetcher,
options,
);
Expand Down Expand Up @@ -106,7 +108,7 @@ const getFeatureSearchFetcher = (params: SearchFeaturesParams) => {
.map(([key, value]) => [key, value.toString()]), // TODO: parsing non-string parameters
),
).toString();
const KEY = `${PREFIX_KEY}${urlSearchParams}`;
const KEY = `${PATH}${urlSearchParams}`;
const fetcher = () => {
const path = formatApiPath(KEY);
return fetch(path, {
Expand Down

0 comments on commit fc95d45

Please sign in to comment.