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

Add chunked transfer support for rendering templates #6580

Conversation

JohnNiang
Copy link
Member

@JohnNiang JohnNiang commented Sep 3, 2024

What type of PR is this?

/kind improvement
/area core
/milestone 2.20.x

What this PR does / why we need it:

This PR adds chunked transfer support for rendering templates, which means that the max memory used by rendering template will be max chunk size instead of size of rendering result.

Users can define the max chunk size like below:

spring:
  thymeleaf:
    reactive:
      maxChunkSize: 8KB # Setting to 0 will disable the chunked response.

Special notes for your reviewer:

  1. Try to start Halo instance

  2. Execute the command like below and see if the response headers contain transfer-encoding: chunked:

    http http://localhost:8090/ -p h
    HTTP/1.1 200 OK
    Cache-Control: no-cache, no-store, max-age=0, must-revalidate
    Content-Language: en-CN
    Content-Type: text/html
    Expires: 0
    Pragma: no-cache
    Referrer-Policy: strict-origin-when-cross-origin
    Vary: Origin
    Vary: Access-Control-Request-Method
    Vary: Access-Control-Request-Headers
    X-Content-Type-Options: nosniff
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 0
    content-encoding: gzip
    set-cookie: XSRF-TOKEN=1e677724-ce82-4b63-911c-f78b22cd9169; Path=/
    transfer-encoding: chunked

Does this PR introduce a user-facing change?

优化模板渲染时所需的内存

@f2c-ci-robot f2c-ci-robot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/improvement Categorizes issue or PR as related to a improvement. labels Sep 3, 2024
@f2c-ci-robot f2c-ci-robot bot added this to the 2.20.x milestone Sep 3, 2024
@f2c-ci-robot f2c-ci-robot bot added the area/core Issues or PRs related to the Halo Core label Sep 3, 2024
@f2c-ci-robot f2c-ci-robot bot requested review from guqing and ruibaby September 3, 2024 11:41
Copy link

sonarqubecloud bot commented Sep 3, 2024

Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.

Project coverage is 58.11%. Comparing base (6cd8dc8) to head (07d9758).
Report is 78 commits behind head on main.

Files with missing lines Patch % Lines
.../run/halo/app/theme/engine/HaloTemplateEngine.java 40.00% 3 Missing ⚠️
...main/java/run/halo/app/theme/HaloViewResolver.java 96.55% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6580      +/-   ##
============================================
- Coverage     58.18%   58.11%   -0.08%     
- Complexity     3774     3919     +145     
============================================
  Files           651      670      +19     
  Lines         22125    22990     +865     
  Branches       1538     1573      +35     
============================================
+ Hits          12873    13360     +487     
- Misses         8641     9012     +371     
- Partials        611      618       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ruibaby
Copy link
Member

ruibaby commented Sep 11, 2024

此 PR 会导致部分插件的功能失效,比如:

  1. https://github.com/webp-sh/halo-plugin-webp-cloud
  2. https://github.com/guqing/plugin-cloudinary

暂不确定是否有其他插件也有类似的问题。

@JohnNiang
Copy link
Member Author

JohnNiang commented Sep 11, 2024

此 PR 会导致部分插件的功能失效,比如:

  1. webp-sh/halo-plugin-webp-cloud
  2. guqing/plugin-cloudinary

暂不确定是否有其他插件也有类似的问题。

失效的插件可以参考 halo-sigs/plugin-page-cache#10 来修复这个问题。另外,这两个需求建议通过 Thymeleaf 的扩展来实现。

@JohnNiang
Copy link
Member Author

/ping @halo-dev/sig-halo

I have refactored plugin plugin-webp-cloud in webp-sh/halo-plugin-webp-cloud#15

Copy link
Member

@guqing guqing left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

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

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Sep 19, 2024
Copy link

f2c-ci-robot bot commented Sep 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: guqing

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 19, 2024
@f2c-ci-robot f2c-ci-robot bot merged commit fb9aff0 into halo-dev:main Sep 19, 2024
8 checks passed
@ruibaby ruibaby modified the milestones: 2.20.x, 2.20.0 LTS Sep 20, 2024
@JohnNiang JohnNiang deleted the feat/support-chunk-response-while-rendering-views branch November 17, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants