Skip to content

Commit

Permalink
parallelize cache fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ah100101 committed Dec 30, 2024
1 parent a5f93e8 commit b794c2c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions core/middlewares/with-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,22 @@ const getRouteInfo = async (request: NextRequest) => {
try {
const pathname = clearLocaleFromPath(request.nextUrl.pathname, locale);

let statusCache = await computeCache.get(`${STORE_STATUS_KEY}:${channelId}`);

if (!statusCache) {
statusCache = await updateStatusCache(channelId, computeCache);
}
const [statusCache, routeCache] = await Promise.all([
computeCache.get(`${STORE_STATUS_KEY}:${channelId}`).then(async (cache) => {
if (!cache) {
return updateStatusCache(channelId, computeCache);
}

let routeCache = await computeCache.get(`${pathname}:${channelId}`);
return cache;
}),
computeCache.get(`${pathname}:${channelId}`).then(async (cache) => {
if (!cache) {
return updateRouteCache(pathname, channelId, computeCache);
}

if (!routeCache) {
routeCache = await updateRouteCache(pathname, channelId, computeCache);
}
return cache;
}),
]);

const parsedRoute = RouteCacheSchema.safeParse(routeCache);
const parsedStatus = StorefrontStatusCacheSchema.safeParse(statusCache);
Expand Down

0 comments on commit b794c2c

Please sign in to comment.