ryoji-s 2 лет назад
Родитель
Сommit
a82414e223
1 измененных файлов с 12 добавлено и 9 удалено
  1. 12 9
      apps/app/src/pages/utils/commons.ts

+ 12 - 9
apps/app/src/pages/utils/commons.ts

@@ -2,6 +2,7 @@ import type { ColorScheme, IUserHasId } from '@growi/core';
 import {
 import {
   DevidedPagePath, Lang, AllLang, isServer,
   DevidedPagePath, Lang, AllLang, isServer,
 } from '@growi/core';
 } from '@growi/core';
+import mongoose from 'mongoose';
 import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
 import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
 import type { SSRConfig, UserConfig } from 'next-i18next';
 import type { SSRConfig, UserConfig } from 'next-i18next';
 
 
@@ -11,7 +12,7 @@ import { detectLocaleFromBrowserAcceptLanguage } from '~/client/util/locale-util
 import type { CrowiRequest } from '~/interfaces/crowi-request';
 import type { CrowiRequest } from '~/interfaces/crowi-request';
 import type { ISidebarConfig } from '~/interfaces/sidebar-config';
 import type { ISidebarConfig } from '~/interfaces/sidebar-config';
 import type { IUserUISettings } from '~/interfaces/user-ui-settings';
 import type { IUserUISettings } from '~/interfaces/user-ui-settings';
-import type { PageDocument } from '~/server/models/page';
+import type { PageModel, PageDocument } from '~/server/models/page';
 import type { UserUISettingsDocument } from '~/server/models/user-ui-settings';
 import type { UserUISettingsDocument } from '~/server/models/user-ui-settings';
 import {
 import {
   useCurrentProductNavWidth, useCurrentSidebarContents, usePreferDrawerModeByUser, usePreferDrawerModeOnEditByUser, useSidebarCollapsed,
   useCurrentProductNavWidth, useCurrentSidebarContents, usePreferDrawerModeByUser, usePreferDrawerModeOnEditByUser, useSidebarCollapsed,
@@ -172,23 +173,25 @@ export const useInitSidebarConfig = (sidebarConfig: ISidebarConfig, userUISettin
   useCurrentProductNavWidth(userUISettings?.currentProductNavWidth);
   useCurrentProductNavWidth(userUISettings?.currentProductNavWidth);
 };
 };
 
 
+async function ensureLatestRevisionBodyLength(page: PageDocument): Promise<number> {
+  if (!page.isLatestRevision() || page.latestRevisionBodyLength == null) {
+    const Page = mongoose.model('Page') as unknown as PageModel;
+    return Page.updateLatestRevisionBodyLength(page._id);
+  }
+
+  return page.latestRevisionBodyLength;
+}
 
 
 export const skipSSR = async(page: PageDocument): Promise<boolean> => {
 export const skipSSR = async(page: PageDocument): Promise<boolean> => {
   if (!isServer()) {
   if (!isServer()) {
     throw new Error('This method is not available on the client-side');
     throw new Error('This method is not available on the client-side');
   }
   }
 
 
-  // page document only stores the bodyLength of the latest revision
-  if (!page.isLatestRevision() || page.latestRevisionBodyLength == null) {
-    return true;
-  }
+  const latestRevisionBodyLength = await ensureLatestRevisionBodyLength(page);
 
 
   const { configManager } = await import('~/server/service/config-manager');
   const { configManager } = await import('~/server/service/config-manager');
   await configManager.loadConfigs();
   await configManager.loadConfigs();
   const ssrMaxRevisionBodyLength = configManager.getConfig('crowi', 'app:ssrMaxRevisionBodyLength');
   const ssrMaxRevisionBodyLength = configManager.getConfig('crowi', 'app:ssrMaxRevisionBodyLength');
-  if (ssrMaxRevisionBodyLength < page.latestRevisionBodyLength) {
-    return true;
-  }
 
 
-  return false;
+  return ssrMaxRevisionBodyLength < latestRevisionBodyLength;
 };
 };