mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
fix: Add default debounce & staleTime to file/folder prefetching (#346)
This commit is contained in:
parent
65d6e928b8
commit
5ebd07ffe1
3 changed files with 27 additions and 8 deletions
|
|
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Text highlighting clarity. [#342](https://github.com/sourcebot-dev/sourcebot/pull/342)
|
- Text highlighting clarity. [#342](https://github.com/sourcebot-dev/sourcebot/pull/342)
|
||||||
- Fixed repo list column header styling. [#344](https://github.com/sourcebot-dev/sourcebot/pull/344)
|
- Fixed repo list column header styling. [#344](https://github.com/sourcebot-dev/sourcebot/pull/344)
|
||||||
- Clean up successful and failed jobs in Redis queues. [#343](https://github.com/sourcebot-dev/sourcebot/pull/343)
|
- Clean up successful and failed jobs in Redis queues. [#343](https://github.com/sourcebot-dev/sourcebot/pull/343)
|
||||||
|
- Fixed issue with files occasionally not loading after moving the cursor rapidly over the file browser. [#346](https://github.com/sourcebot-dev/sourcebot/pull/346)
|
||||||
|
|
||||||
## [4.2.0] - 2025-06-09
|
## [4.2.0] - 2025-06-09
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,21 @@ import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { useDomain } from "./useDomain";
|
import { useDomain } from "./useDomain";
|
||||||
import { unwrapServiceError } from "@/lib/utils";
|
import { unwrapServiceError } from "@/lib/utils";
|
||||||
import { getFileSource } from "@/features/search/fileSourceApi";
|
import { getFileSource } from "@/features/search/fileSourceApi";
|
||||||
import { useCallback } from "react";
|
import { useDebounceCallback } from "usehooks-ts";
|
||||||
|
|
||||||
export const usePrefetchFileSource = () => {
|
interface UsePrefetchFileSourceProps {
|
||||||
|
debounceDelay?: number;
|
||||||
|
staleTime?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const usePrefetchFileSource = ({
|
||||||
|
debounceDelay = 200,
|
||||||
|
staleTime = 5 * 60 * 1000, // 5 minutes
|
||||||
|
}: UsePrefetchFileSourceProps = {}) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const domain = useDomain();
|
const domain = useDomain();
|
||||||
|
|
||||||
const prefetchFileSource = useCallback((repoName: string, revisionName: string, path: string) => {
|
const prefetchFileSource = useDebounceCallback((repoName: string, revisionName: string, path: string) => {
|
||||||
queryClient.prefetchQuery({
|
queryClient.prefetchQuery({
|
||||||
queryKey: ['fileSource', repoName, revisionName, path, domain],
|
queryKey: ['fileSource', repoName, revisionName, path, domain],
|
||||||
queryFn: () => unwrapServiceError(getFileSource({
|
queryFn: () => unwrapServiceError(getFileSource({
|
||||||
|
|
@ -18,8 +26,9 @@ export const usePrefetchFileSource = () => {
|
||||||
repository: repoName,
|
repository: repoName,
|
||||||
branch: revisionName,
|
branch: revisionName,
|
||||||
}, domain)),
|
}, domain)),
|
||||||
|
staleTime,
|
||||||
});
|
});
|
||||||
}, [queryClient, domain]);
|
}, debounceDelay);
|
||||||
|
|
||||||
return { prefetchFileSource };
|
return { prefetchFileSource };
|
||||||
}
|
}
|
||||||
|
|
@ -3,14 +3,22 @@
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { useDomain } from "./useDomain";
|
import { useDomain } from "./useDomain";
|
||||||
import { unwrapServiceError } from "@/lib/utils";
|
import { unwrapServiceError } from "@/lib/utils";
|
||||||
import { useCallback } from "react";
|
|
||||||
import { getFolderContents } from "@/features/fileTree/actions";
|
import { getFolderContents } from "@/features/fileTree/actions";
|
||||||
|
import { useDebounceCallback } from "usehooks-ts";
|
||||||
|
|
||||||
export const usePrefetchFolderContents = () => {
|
interface UsePrefetchFolderContentsProps {
|
||||||
|
debounceDelay?: number;
|
||||||
|
staleTime?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const usePrefetchFolderContents = ({
|
||||||
|
debounceDelay = 200,
|
||||||
|
staleTime = 5 * 60 * 1000, // 5 minutes
|
||||||
|
}: UsePrefetchFolderContentsProps = {}) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const domain = useDomain();
|
const domain = useDomain();
|
||||||
|
|
||||||
const prefetchFolderContents = useCallback((repoName: string, revisionName: string, path: string) => {
|
const prefetchFolderContents = useDebounceCallback((repoName: string, revisionName: string, path: string) => {
|
||||||
queryClient.prefetchQuery({
|
queryClient.prefetchQuery({
|
||||||
queryKey: ['tree', repoName, revisionName, path, domain],
|
queryKey: ['tree', repoName, revisionName, path, domain],
|
||||||
queryFn: () => unwrapServiceError(
|
queryFn: () => unwrapServiceError(
|
||||||
|
|
@ -20,8 +28,9 @@ export const usePrefetchFolderContents = () => {
|
||||||
path,
|
path,
|
||||||
}, domain)
|
}, domain)
|
||||||
),
|
),
|
||||||
|
staleTime,
|
||||||
});
|
});
|
||||||
}, [queryClient, domain]);
|
}, debounceDelay);
|
||||||
|
|
||||||
return { prefetchFolderContents };
|
return { prefetchFolderContents };
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue