Refactor cache functions to use explicit loaders
The commit refactors the previous implementation of using cache functions across several modules. They are now explicitly defined as loaders to improve readability and maintain a consistent style. This prevents the cache function calls from getting too nested and difficult to understand, especially in asynchronous cases. Additionally, the user session related hooks are deleted which were not used anymore.
This commit is contained in:
@@ -18,7 +18,9 @@ export type UserWorkspace = Awaited<ReturnType<typeof loadUserWorkspace>>;
|
||||
* Load the user workspace data. It's a cached per-request function that fetches the user workspace data.
|
||||
* It can be used across the server components to load the user workspace data.
|
||||
*/
|
||||
export const loadUserWorkspace = cache(async () => {
|
||||
export const loadUserWorkspace = cache(workspaceLoader);
|
||||
|
||||
async function workspaceLoader() {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const api = createAccountsApi(client);
|
||||
|
||||
@@ -45,4 +47,4 @@ export const loadUserWorkspace = cache(async () => {
|
||||
workspace,
|
||||
user,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,11 @@ const BILLING_MODE = z
|
||||
* @returns The subscription data or the orders data and the billing customer ID.
|
||||
* This function is cached per-request.
|
||||
*/
|
||||
export const loadPersonalAccountBillingPageData = cache((userId: string) => {
|
||||
export const loadPersonalAccountBillingPageData = cache(
|
||||
personalAccountBillingPageDataLoader,
|
||||
);
|
||||
|
||||
function personalAccountBillingPageDataLoader(userId: string) {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const api = createAccountsApi(client);
|
||||
|
||||
@@ -40,4 +44,4 @@ export const loadPersonalAccountBillingPageData = cache((userId: string) => {
|
||||
const customerId = api.getCustomerId(userId);
|
||||
|
||||
return Promise.all([data, customerId]);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user