Просмотр исходного кода

improve identical path page checking

Yuki Takei 7 месяцев назад
Родитель
Сommit
1a40ca1f02
1 измененных файлов с 34 добавлено и 33 удалено
  1. 34 33
      apps/app/src/pages/[[...path]]/page-data-props.ts

+ 34 - 33
apps/app/src/pages/[[...path]]/page-data-props.ts

@@ -38,31 +38,31 @@ export async function getPageDataForInitial(
 
   let currentPathname = pathFromUrl;
 
-  // Check for redirects
+  // Check for redirects and whether the path is identical
   if (!isPermalink) {
     const chains = await PageRedirect.retrievePageRedirectEndpoints(pathFromUrl);
     if (chains != null) {
       currentPathname = chains.end.toPath;
     }
-  }
-
-  // Check multiple pages hits
-  const multiplePagesCount = await Page.countByPathAndViewer(currentPathname, user, null, true);
-  const isIdenticalPathPage = multiplePagesCount > 1;
 
-  // Early return for identical path pages
-  if (isIdenticalPathPage) {
-    return {
-      props: {
-        currentPathname,
-        isIdenticalPathPage: true,
-        pageWithMeta: null,
-        isNotFound: false,
-        isNotCreatable: true,
-        isForbidden: false,
-        skipSSR: false,
-      },
-    };
+    // Check multiple pages hits
+    const multiplePagesCount = await Page.countByPathAndViewer(currentPathname, user, null, true);
+    const isIdenticalPathPage = multiplePagesCount > 1;
+
+    // Early return for identical path pages
+    if (isIdenticalPathPage) {
+      return {
+        props: {
+          currentPathname,
+          isIdenticalPathPage: true,
+          pageWithMeta: null,
+          isNotFound: false,
+          isNotCreatable: true,
+          isForbidden: false,
+          skipSSR: false,
+        },
+      };
+    }
   }
 
   // Get full page data
@@ -154,27 +154,28 @@ export async function getPageDataForSameRoute(
   let resolvedPathname = currentPathname;
   let redirectFrom: string | undefined;
 
+  // Check for redirects and whether the path is identical
   if (!isPermalink) {
     const chains = await PageRedirect.retrievePageRedirectEndpoints(currentPathname);
     if (chains != null) {
       resolvedPathname = chains.end.toPath;
       redirectFrom = chains.start.fromPath;
     }
-  }
-
-  // Check multiple pages hits
-  const multiplePagesCount = await Page.countByPathAndViewer(resolvedPathname, user, null, true);
-  const isIdenticalPathPage = multiplePagesCount > 1;
 
-  // Early return for identical path pages
-  if (isIdenticalPathPage) {
-    return {
-      props: {
-        currentPathname: resolvedPathname,
-        isIdenticalPathPage: true,
-        redirectFrom,
-      },
-    };
+    // Check multiple pages hits
+    const multiplePagesCount = await Page.countByPathAndViewer(resolvedPathname, user, null, true);
+    const isIdenticalPathPage = multiplePagesCount > 1;
+
+    // Early return for identical path pages
+    if (isIdenticalPathPage) {
+      return {
+        props: {
+          currentPathname: resolvedPathname,
+          isIdenticalPathPage: true,
+          redirectFrom,
+        },
+      };
+    }
   }
 
   // For same route access, do minimal page lookup