Skip to content

Commit 700c5f7

Browse files
no-store caching strategy
1 parent 35edfa0 commit 700c5f7

5 files changed

Lines changed: 21 additions & 26 deletions

File tree

src/app/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client';
2-
31
import Image from "next/image";
42
import logoDark from "../../public/sb_logo_dark_large.png";
53
import logoLight from "../../public/sb_logo_light_large.png";

src/app/repos/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
'use client';
2-
1+
import { Suspense } from "react";
32
import { NavigationMenu } from "../navigationMenu";
43
import { RepositoryTable } from "./repositoryTable";
54

65
export default function ReposPage() {
76
return (
87
<div className="h-screen flex flex-col items-center">
98
<NavigationMenu />
10-
<RepositoryTable />
9+
<Suspense fallback={<div>Loading...</div>}>
10+
<RepositoryTable />
11+
</Suspense>
1112
</div>
1213
)
1314
}

src/app/repos/repositoryTable.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
'use client';
2-
31
import { DataTable } from "@/components/ui/data-table";
42
import { columns, RepositoryColumnInfo } from "./columns";
3+
import { listRepositories } from "@/lib/server/searchService";
54
import { isServiceError } from "@/lib/utils";
6-
import { useQuery } from "@tanstack/react-query";
7-
import { useMemo } from "react";
8-
import { getRepos } from "../api/(client)/client";
95

10-
export const RepositoryTable = () => {
11-
const { data: _repos } = useQuery({
12-
queryKey: ["repos"],
13-
queryFn: () => getRepos(),
14-
enabled: typeof window !== "undefined",
15-
});
6+
export const RepositoryTable = async () => {
7+
const _repos = await listRepositories();
168

17-
const repos = useMemo(() => {
18-
if (isServiceError(_repos)) {
19-
return [];
20-
}
9+
if (isServiceError(_repos)) {
10+
return <div>Error fetching repositories</div>;
11+
}
2112

22-
return _repos?.List.Repos.map((repo): RepositoryColumnInfo => ({
13+
const repos = _repos.List.Repos.map((repo): RepositoryColumnInfo => {
14+
return {
2315
name: repo.Repository.Name,
2416
branches: repo.Repository.Branches.map((branch) => {
2517
return {
@@ -34,10 +26,10 @@ export const RepositoryTable = () => {
3426
latestCommit: repo.Repository.LatestCommitDate,
3527
indexedFiles: repo.Stats.Documents,
3628
commitUrlTemplate: repo.Repository.CommitURLTemplate,
37-
})).sort((a, b) => {
38-
return new Date(b.lastIndexed).getTime() - new Date(a.lastIndexed).getTime();
39-
}) ?? [];
40-
}, [_repos]);
29+
}
30+
}).sort((a, b) => {
31+
return new Date(b.lastIndexed).getTime() - new Date(a.lastIndexed).getTime();
32+
});
4133

4234
return (
4335
<DataTable

src/lib/server/searchService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export const listRepositories = async (): Promise<ListRepositoriesResponse | Ser
7474
const listResponse = await zoektFetch({
7575
path: "/api/list",
7676
body,
77-
method: "POST"
77+
method: "POST",
78+
cache: "no-store",
7879
});
7980

8081
if (!listResponse.ok) {

src/lib/server/zoektClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ interface ZoektRequest {
55
path: string,
66
body: string,
77
method: string,
8+
cache?: RequestCache,
89
}
910

1011
export const zoektFetch = async ({
1112
path,
1213
body,
1314
method,
15+
cache,
1416
}: ZoektRequest) => {
1517
const start = Date.now();
1618

@@ -22,6 +24,7 @@ export const zoektFetch = async ({
2224
"Content-Type": "application/json",
2325
},
2426
body,
27+
cache,
2528
}
2629
);
2730

0 commit comments

Comments
 (0)