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

Improve Boilerplate response caching (#9782) #9783

Merged
merged 5 commits into from
Feb 3, 2025

Conversation

ysmoradi
Copy link
Member

@ysmoradi ysmoradi commented Feb 2, 2025

closes #9782

Summary by CodeRabbit

  • New Features

    • Introduced dynamic control of stream prerendering to optimize content rendering.
    • Adjusted sitemap responses to correctly signal XML content, enhancing browser and crawler compatibility.
  • Documentation

    • Improved inline guidance across caching and content delivery processes for clearer behavior descriptions.
  • Refactor

    • Refined caching conditions to better manage content eligibility and performance.
    • Updated conditional logic to ensure more accurate rendering based on request characteristics.

@ysmoradi ysmoradi requested a review from msynk February 2, 2025 12:33
Copy link

coderabbitai bot commented Feb 2, 2025

Walkthrough

The changes update XML documentation and refine logic in caching and rendering components. The modifications include condition changes in cache handling, updates to the context for stream prerendering control, and an adjustment in the rendering logic for pre-rendering based on the new method. Additionally, a new extension method and header setting improvements for sitemap endpoints have been introduced.

Changes

File(s) Change Summary
src/Templates/Boilerplate/Bit.Boilerplate/.../Services/AppResponseCachePolicy.cs (Api & Web) Added XML documentation to the class and its methods; modified CacheRequestAsync condition from if(outputCacheTtl != -1) to if(outputCacheTtl > 0); added context item for disabling stream prerendering; included conditional compilation comments.
src/Templates/Boilerplate/Bit.Boilerplate/.../Components/App.razor Replaced IsCrawlerClient() check with DisableStreamPrerendering() for conditional rendering of stream containers.
src/Templates/Boilerplate/Bit.Boilerplate/.../Extensions/HttpRequestExtensions.cs Introduced a new method DisableStreamPrerendering to determine if stream pre-rendering should be disabled based on context items.
src/Templates/Boilerplate/Bit.Boilerplate/.../Program.Middlewares.cs Added a header assignment to set Content-Type as "application/xml" for sitemap endpoints.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant AR as App.razor
    participant HT as HttpRequestExtensions
    C->>AR: Send request
    AR->>HT: Call DisableStreamPrerendering()
    HT-->>AR: Return boolean flag
    alt Prerendering Disabled
      AR->>AR: Render StreamRenderingDisabledContainer
    else Prerendering Enabled
      AR->>AR: Render StreamRenderingEnabledContainer
    end
Loading
sequenceDiagram
    participant C as Client
    participant AP as AppResponseCachePolicy
    participant CM as Cache Middleware
    C->>AP: Invoke CacheRequestAsync(context)
    AP->>AP: Check (outputCacheTtl > 0)
    AP->>Context: Set "DisableStreamPrerendering" flag
    AP->>CM: Continue caching process
Loading

Assessment against linked issues

Objective Addressed Explanation
Improve caching and stream prerendering logic (#9776)
Enhance XML documentation for caching mechanisms (#9776)
Correct sitemap response Content-Type header (#9776)

Poem

In code I hop with joyful might,
New docs and logic shining bright.
Caches refined with a careful tweak,
Prerendering flows now calm, not weak.
A rabbit’s cheer in ASCII delight 🐇✨!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ysmoradi ysmoradi marked this pull request as ready for review February 2, 2025 13:45
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Extensions/HttpRequestExtensions.cs (1)

31-37: LGTM! Consider adding XML documentation.

The method logic is correct and aligns with the caching improvements. Consider adding XML documentation to explain the method's purpose and return value.

+    /// <summary>
+    /// Determines if stream prerendering should be disabled based on caching policy or crawler client status.
+    /// </summary>
+    /// <returns>True if stream prerendering should be disabled; otherwise, false.</returns>
 public static bool DisableStreamPrerendering(this HttpRequest request)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Services/AppResponseCachePolicy.cs (1)

93-93: Consider using a constant for the context item key.

The string literal "AppResponseCachePolicy__DisableStreamPrerendering" is used in multiple places. Consider extracting it to a constant to prevent typos and improve maintainability.

+    private const string DisableStreamPrerenderingKey = "AppResponseCachePolicy__DisableStreamPrerendering";

Then use it in the code:

-    context.HttpContext.Items["AppResponseCachePolicy__DisableStreamPrerendering"] = outputCacheTtl > 0 || edgeCacheTtl > 0;
+    context.HttpContext.Items[DisableStreamPrerenderingKey] = outputCacheTtl > 0 || edgeCacheTtl > 0;
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.Middlewares.cs (1)

205-205: LGTM! Consider using ContentType constants.

The addition of the ContentType header is correct and necessary for proper XML handling.

Consider using Microsoft.Net.Http.Headers.MediaTypeHeaderValue.ApplicationXml.ToString() for better maintainability:

-context.Response.Headers.ContentType = "application/xml";
+context.Response.Headers.ContentType = Microsoft.Net.Http.Headers.MediaTypeHeaderValue.ApplicationXml.ToString();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 886c97e and 0912b22.

📒 Files selected for processing (5)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/AppResponseCachePolicy.cs (3 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Components/App.razor (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Extensions/HttpRequestExtensions.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.Middlewares.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Services/AppResponseCachePolicy.cs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (4)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Components/App.razor (1)

68-68: LGTM! Improved rendering control based on caching policy.

The change correctly uses the new DisableStreamPrerendering() method to determine rendering behavior, considering both caching policy and crawler status.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Services/AppResponseCachePolicy.cs (1)

85-91: LGTM! Improved cache TTL condition.

The condition change from != -1 to > 0 is more precise and better expresses the intent.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/AppResponseCachePolicy.cs (1)

95-97: LGTM! Proper conditional compilation for API integration.

The stream prerendering context item is correctly wrapped in conditional compilation directives for API integration scenarios.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.Middlewares.cs (1)

189-254: LGTM! Well-designed caching strategy.

The caching configuration is well-structured with appropriate durations:

  • 7 days for static sitemaps
  • 5 minutes for dynamic product sitemap

This balances performance with content freshness.

@msynk msynk merged commit e7cd8af into bitfoundation:develop Feb 3, 2025
3 checks passed
@msynk msynk changed the title Improve Boilerplate response caching (#9776) Improve Boilerplate response caching (#9782) Feb 3, 2025
@ysmoradi ysmoradi deleted the 9776 branch February 5, 2025 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boilerplate project template's response caching needs improvements
2 participants