Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imprv: Improve default behavior of skipSSR #7927

Merged
merged 7 commits into from
Jul 31, 2023

Conversation

jam411
Copy link
Contributor

@jam411 jam411 commented Jul 28, 2023

実装方針

  1. 先に page に latestRevisionBodyLength フィールドがあるかないかを確認する
  2. なければそのページに対して model 層のメソッドで revision から latestRevisioinBodyLength を取得 + Page モデルのフィールドに追加
  3. この後に skip ssr するかの閾値判断

@jam411 jam411 requested a review from yuki-takei July 28, 2023 08:46
@jam411 jam411 self-assigned this Jul 28, 2023
@jam411 jam411 temporarily deployed to VRT July 28, 2023 09:03 — with GitHub Actions Inactive
apps/app/src/pages/utils/commons.ts Outdated Show resolved Hide resolved
apps/app/src/server/models/page.ts Outdated Show resolved Hide resolved
apps/app/src/server/models/page.ts Show resolved Hide resolved
apps/app/src/server/models/page.ts Outdated Show resolved Hide resolved
apps/app/src/server/models/page.ts Outdated Show resolved Hide resolved
apps/app/src/pages/utils/commons.ts Outdated Show resolved Hide resolved
@jam411 jam411 temporarily deployed to VRT July 29, 2023 11:03 — with GitHub Actions Inactive
@@ -959,6 +960,37 @@ schema.statics.findNonEmptyClosestAncestor = async function(path: string): Promi
return ancestors[0];
};

export async function calculateAndUpdateLatestRevisionBodyLength(page: PageDocument): Promise<number | null> {
const latestRevisionData = await mongoose.model('Revision').findById(page.revision, { body: 1 });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは populate で書けない?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model 層で populate は NG だと思っていました。populate するように変更してみました。

apps/app/src/server/models/page.ts Outdated Show resolved Hide resolved
apps/app/src/server/models/page.ts Outdated Show resolved Hide resolved
@jam411 jam411 temporarily deployed to VRT July 30, 2023 12:27 — with GitHub Actions Inactive
// Infer the type as Omit<PageDocument, never> due to the population
// Cast the type back to PageDocument to restore the original type
// eslint-disable-next-line rulesdir/no-populate
const populatedPageDocument = await this.populate('revision', 'body') as PageDocument;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const populatedPageDocument = await this.populate<PageDocument>('revision', 'body');


if (typeof populatedPageDocument.revision === 'string') {
throw new Error('Failed to populate revision field in the page document.');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • @growi/core package の isPopulated を使う
  • assert(isPopulated(...)) でOK

/*
* get latest revision body length
*/
schema.methods.getLatestRevisionBodyLength = async function(this: PageDocument): Promise<number | null | undefined> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined が返ることってある?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this.latestRevisionBodyLength がもともと number | undefined 型なので undefined も許容しないと最後の return this.latestRevisionBodyLength; で型エラーになるためこうしました。
    確かに値が入っているか null かどうかなことは getLatestRevisionBodyLength すれば分かるので undefined が返りえるのが気持ち悪い感じもします。
    ただ考えてみると、実際 latestRevisionBodyLength フィールドに null を格納するわけではないのでむしろ undefined を返すほうが正しいんでしょうかね?

  • calculateAndUpdateLatestRevisionBodyLength が結果を返すようにすれば解決しそうですが、calculateAndUpdate の接頭語のメソッドに結果を返す責務も持たせていいのかわからなかったのでこうしていました。

const latestRevisionBodyLength = await page.getLatestRevisionBodyLength();

if (latestRevisionBodyLength == null) {
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここ return true では?
過去の revision 閲覧時は多少 UX 落ちても良くて、それより重いかもしれないデータを SSR しない方が安全だよね。

Copy link
Contributor Author

@jam411 jam411 Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうか、過去の revision を見る場合は安全ですね。
return true で SSR しないようにします。

@jam411 jam411 temporarily deployed to VRT July 30, 2023 15:50 — with GitHub Actions Inactive
@reg-suit
Copy link

reg-suit bot commented Jul 30, 2023

reg-suit detected visual differences.

Check this report, and review them.

🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴

🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵

What do the circles mean? The number of circles represent the number of changed images.
🔴 : Changed items, ⚪ : New items, ⚫ : Deleted items, and 🔵 Passed items

How can I change the check status? If reviewers approve this PR, the reg context status will be green automatically.

@yuki-takei yuki-takei merged commit 52b3d80 into master Jul 31, 2023
24 checks passed
@yuki-takei yuki-takei deleted the imprv/127287-127291-skip-ssr-default branch July 31, 2023 05:53
This was referenced Jul 31, 2023
@github-actions github-actions bot mentioned this pull request Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants