1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-06 01:15:28 +02:00

feat: use different cache key for command bar (#7530)

Now command bar and search do not share same cache, so they wont
conflict anymore.
This commit is contained in:
Jaanus Sellin 2024-07-03 14:28:47 +03:00 committed by GitHub
parent d924519abb
commit fc95d459d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -23,6 +23,7 @@ export const CommandSearchFeatures = ({
{ {
revalidateOnFocus: false, revalidateOnFocus: false,
}, },
'command-bar-cache',
); );
const flags: CommandResultGroupItem[] = features.map((feature) => ({ const flags: CommandResultGroupItem[] = features.map((feature) => ({

View File

@ -26,7 +26,7 @@ const fallbackData: SearchFeaturesSchema = {
}; };
const SWR_CACHE_SIZE = 10; const SWR_CACHE_SIZE = 10;
const PREFIX_KEY = 'api/admin/search/features?'; const PATH = 'api/admin/search/features?';
const createFeatureSearch = () => { const createFeatureSearch = () => {
const internalCache: InternalCache = {}; const internalCache: InternalCache = {};
@ -55,17 +55,19 @@ const createFeatureSearch = () => {
return ( return (
params: SearchFeaturesParams, params: SearchFeaturesParams,
options: SWRConfiguration = {}, options: SWRConfiguration = {},
cachePrefix: string = '',
): UseFeatureSearchOutput => { ): UseFeatureSearchOutput => {
const { KEY, fetcher } = getFeatureSearchFetcher(params); const { KEY, fetcher } = getFeatureSearchFetcher(params);
const swrKey = `${cachePrefix}${KEY}`;
const cacheId = params.project || ''; const cacheId = params.project || '';
useClearSWRCache(KEY, PREFIX_KEY, SWR_CACHE_SIZE); useClearSWRCache(swrKey, PATH, SWR_CACHE_SIZE);
useEffect(() => { useEffect(() => {
initCache(params.project || ''); initCache(params.project || '');
}, []); }, []);
const { data, error, mutate, isLoading } = useSWR<SearchFeaturesSchema>( const { data, error, mutate, isLoading } = useSWR<SearchFeaturesSchema>(
KEY, swrKey,
fetcher, fetcher,
options, options,
); );
@ -106,7 +108,7 @@ const getFeatureSearchFetcher = (params: SearchFeaturesParams) => {
.map(([key, value]) => [key, value.toString()]), // TODO: parsing non-string parameters .map(([key, value]) => [key, value.toString()]), // TODO: parsing non-string parameters
), ),
).toString(); ).toString();
const KEY = `${PREFIX_KEY}${urlSearchParams}`; const KEY = `${PATH}${urlSearchParams}`;
const fetcher = () => { const fetcher = () => {
const path = formatApiPath(KEY); const path = formatApiPath(KEY);
return fetch(path, { return fetch(path, {