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

use existing method to check if the page.revision is latest

yohei0125 3 лет назад
Родитель
Сommit
f28c15e7b1
1 измененных файлов с 2 добавлено и 11 удалено
  1. 2 11
      packages/app/src/pages/[[...path]].page.tsx

+ 2 - 11
packages/app/src/pages/[[...path]].page.tsx

@@ -314,10 +314,11 @@ async function getPageData(context: GetServerSidePropsContext, props: Props): Pr
   const result: IPageWithMeta = await pageService.findPageAndMetaDataByViewer(pageId, currentPathname, user, true); // includeEmpty = true, isSharedPage = false
   const page = result?.data as unknown as PageDocument;
 
-  // populate
+  // populate & check if the revision is latest
   if (page != null) {
     page.initLatestRevisionField(revisionId);
     await page.populateDataToShowRevision();
+    props.isLatestRevision = page.isLatestRevision();
   }
 
   return result;
@@ -442,16 +443,6 @@ export const getServerSideProps: GetServerSideProps = async(context: GetServerSi
     }
   }
 
-  // check revision
-  const isSpecifiedRevisionExist = await crowi.revisionService.isSpecifiedRevisionExist(revisionId);
-  const page = pageWithMeta?.data;
-  if (page == null || page.latestRevision == null || revisionId == null || !isSpecifiedRevisionExist) {
-    props.isLatestRevision = true;
-  }
-  else {
-    props.isLatestRevision = page.latestRevision.toString() === revisionId;
-  }
-
   injectRoutingInformation(context, props, pageWithMeta);
   injectServerConfigurations(context, props);