perf(board): deduplicate board fetch with React cache()
Wrap getInitialBoardAsync in React cache() so the same board data is fetched once per request instead of 3 times (layout, page, metadata). This is the same pattern used for auth() in the codebase.
This commit is contained in:
2 files changed
+10
-6
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import { cache } from "react";
|
||||
|
||||
import { api } from "@homarr/api/server";
|
||||
|
||||
import { createBoardContentPage } from "../_creator";
|
||||
|
||||
const getHomeBoardAsync = cache(() => api.board.getHomeBoard());
|
||||
|
||||
export default createBoardContentPage<{ locale: string }>({
|
||||
async getInitialBoardAsync() {
|
||||
return await api.board.getHomeBoard();
|
||||
},
|
||||
getInitialBoardAsync: getHomeBoardAsync,
|
||||
});
|
||||
@@ -1,9 +1,11 @@
|
||||
import { cache } from "react";
|
||||
|
||||
import { api } from "@homarr/api/server";
|
||||
|
||||
import { createBoardContentPage } from "../../_creator";
|
||||
|
||||
const getBoardByNameAsync = cache((name: string) => api.board.getBoardByName({ name }));
|
||||
|
||||
export default createBoardContentPage<{ locale: string; name: string }>({
|
||||
async getInitialBoardAsync({ name }) {
|
||||
return await api.board.getBoardByName({ name });
|
||||
},
|
||||
getInitialBoardAsync: ({ name }) => getBoardByNameAsync(name),
|
||||
});
|
||||
Reference in new issue
Block a user