Skip to content

Conversation

@amotl
Copy link
Member

@amotl amotl commented May 10, 2025

About

When accessing documentation resources through HTTP, they don't need to be fetched over and over again, as they will not change that often. A cache TTL of one hour keeps a good balance between saving resources, and resource freshness. wdyt?

Review

Note

That's a stacked PR. GH-9 will need to go in first.

@coderabbitai
Copy link

coderabbitai bot commented May 10, 2025

Walkthrough

The updates introduce the hishel library to enable HTTP response caching for CrateDB documentation fetches, using a local SQLite cache with a configurable TTL. The .gitignore is updated to ignore all .sqlite files. The changelog is revised to reflect these changes, and the new dependency is added to pyproject.toml. The README and settings are updated to document the new cache TTL configuration.

Changes

File(s) Change Summary
.gitignore Added *.sqlite under a new "Databases" section to ignore all SQLite database files.
CHANGES.md Updated MCP docs wording and added note about Hishel caching with configurable cache TTL.
cratedb_mcp/main.py Integrated hishel for HTTP caching in documentation fetches, using SQLite storage with TTL.
pyproject.toml Added hishel<0.2 as a required dependency.
README.md Added description of CRATEDB_MCP_DOCS_CACHE_TTL environment variable for cache TTL.
cratedb_mcp/settings.py Added DOCS_CACHE_TTL setting reading from environment variable with default 3600 seconds and warning on invalid values.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainScript
    participant CacheClient (hishel)
    participant RemoteServer

    User->>MainScript: Run fetch_cratedb_docs
    MainScript->>CacheClient (hishel): client.get(url)
    alt Cache hit and valid
        CacheClient (hishel)-->>MainScript: Return cached response
    else Cache miss or stale
        CacheClient (hishel)->>RemoteServer: HTTP GET url
        RemoteServer-->>CacheClient (hishel): Response
        CacheClient (hishel)-->>MainScript: Return fresh response
    end
Loading

Poem

In burrows deep, a cache I keep,
With Hishel’s help, my docs don’t sleep.
SQLite files I now ignore,
My changelog’s fresh, dependencies more.
With every hop, I fetch with glee—
Fast docs for all, as quick as me!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0fc943a and 85fbcdd.

📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • CHANGES.md (1 hunks)
  • README.md (1 hunks)
  • cratedb_mcp/__main__.py (2 hunks)
  • cratedb_mcp/settings.py (1 hunks)
  • pyproject.toml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • .gitignore
  • pyproject.toml
  • README.md
  • cratedb_mcp/main.py
  • cratedb_mcp/settings.py
  • CHANGES.md
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@amotl amotl requested review from kneth and surister May 10, 2025 13:19
@amotl amotl marked this pull request as ready for review May 10, 2025 13:19
Copy link
Member

@surister surister left a comment

Choose a reason for hiding this comment

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

LGTM

Base automatically changed from boilerplate to main May 10, 2025 17:39
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 (2)
cratedb_mcp/settings.py (2)

5-5: Consider adding error handling for non-integer environment variable values.

The current implementation will raise a ValueError if CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL contains a non-integer value. Consider adding a try-except block to handle this case gracefully.

- HTTP_CLIENT_CACHE_TTL: int = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600"))
+ try:
+     HTTP_CLIENT_CACHE_TTL: int = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600"))
+ except ValueError:
+     # If the environment variable is not a valid integer, use the default value
+     HTTP_CLIENT_CACHE_TTL: int = 3600

5-5: Consider adding value validation for the TTL setting.

It might be beneficial to validate that the TTL value is positive and within a reasonable range. Very short TTLs might defeat the purpose of caching, while extremely long TTLs could lead to stale data.

- HTTP_CLIENT_CACHE_TTL: int = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600"))
+ # Get TTL value from environment or use default of 1 hour
+ ttl_raw = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600"))
+ # Ensure TTL is at least 1 second and at most 24 hours (86400 seconds)
+ HTTP_CLIENT_CACHE_TTL: int = max(1, min(ttl_raw, 86400))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 456398a and 0fc943a.

📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • CHANGES.md (1 hunks)
  • README.md (1 hunks)
  • cratedb_mcp/__main__.py (2 hunks)
  • cratedb_mcp/settings.py (1 hunks)
  • pyproject.toml (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • .gitignore
  • README.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • cratedb_mcp/main.py
  • pyproject.toml
  • CHANGES.md
🔇 Additional comments (1)
cratedb_mcp/settings.py (1)

4-5: LGTM: Clean addition of HTTP client cache TTL setting.

The new setting HTTP_CLIENT_CACHE_TTL is well-named and follows the existing pattern of reading from environment variables with sensible defaults. The default value of 3600 seconds (1 hour) aligns with the PR objective of balancing resource savings with content freshness.

By default, configure cache lifetime to one hour.
Use the `CRATEDB_MCP_DOCS_CACHE_TTL` environment variable to adjust
(default: 3600).
@amotl amotl merged commit 4f122fd into main May 10, 2025
6 checks passed
@amotl amotl deleted the docs-caching branch May 10, 2025 17:53
Copy link
Member

@kneth kneth left a comment

Choose a reason for hiding this comment

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

👍🏻

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.

4 participants