8000 feat: support schema cache. by ya7010 · Pull Request #641 · tombi-toml/tombi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: support schema cache. #641

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

Merged
merged 14 commits into from
Jul 4, 2025
Merged

feat: support schema cache. #641

merged 14 commits into from
Jul 4, 2025

Conversation

ya7010
Copy link
Collaborator
@ya7010 ya7010 commented Jul 4, 2025

Support #624

@Copilot Copilot AI review requested due to automatic review settings July 4, 2025 13:42
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for local caching of fetched schemas and catalogs by introducing a new tombi-cache crate, integrating a cache_ttl option throughout the schema store, and wiring default TTL values into CLI and LSP commands.

  • Introduce tombi-cache crate for file-based caching.
  • Extend SchemaStore to read from and write to cache for HTTP schema/catalog fetches.
  • Propagate DEFAULT_CACHE_TTL into CLI and LSP commands.

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rust/tombi-cli/src/app/command/lint.rs Pass cache_ttl default to SchemaStore options
rust/tombi-cli/src/app/command/format.rs Pass cache_ttl default to SchemaStore options
crates/tombi-schema-store/src/store.rs Add catalog/schema caching logic and refactor fetch methods
crates/tombi-schema-store/src/options.rs Add cache_ttl field and DEFAULT_CACHE_TTL constant
crates/tombi-schema-store/src/lib.rs Export DEFAULT_CACHE_TTL
crates/tombi-schema-store/src/error.rs Add CacheError variant
crates/tombi-schema-store/Cargo.toml Add tombi-cache as dependency
crates/tombi-lsp/src/backend.rs Wire DEFAULT_CACHE_TTL into LSP backend
crates/tombi-cache/src/lib.rs Implement cache directory, read and save utilities
crates/tombi-cache/src/error.rs Define cache error types and codes
crates/tombi-cache/Cargo.toml Define tombi-cache crate metadata
Cargo.toml Add tombi-cache workspace dependency
Comments suppressed due to low confidence (3)

crates/tombi-schema-store/src/store.rs:145

  • The new catalog caching branches (cache hit, cache miss, TTL expiry) lack unit tests; consider adding tests in tombi-schema-store and tombi-cache to verify correct behavior under different TTL and offline scenarios.
                    read_from_cache(catalog_cache_path.as_deref(), self.options.cache_ttl)?

crates/tombi-schema-store/src/store.rs:254

  • .transpose() is not defined on a Result<Option<T>, E>; consider unwrapping the Result first and then handling the Option with match or and_then.
            if let Some(document_schema) = self.fetch_document_schema(schema_url).await.transpose()

crates/tombi-schema-store/src/store.rs:386

  • The call to .transpose() on Result<Option<DocumentSchema>, Error> will not compile; you need to handle the Result and Option separately (e.g., let res = self.fetch_document_schema(...).await?; if let Some(schema) = res { ... }).
            match self.fetch_document_schema(schema_url).await.transpose() {

ya7010 added 12 commits July 4, 2025 23:06
Updated cache operations to use async functions with Tokio for improved performance and non-blocking behavior. Added Tokio as a dependency in the project.
Updated cache-related functions to be asynchronous, allowing for non-blocking operations when accessing and creating cache directories and files. Adjusted dependencies in Cargo.toml to reflect the necessary Tokio features.
This commit introduces a new `no_cache` option to the command-line interface and backend options, allowing users to disable caching when running commands. The `no_cache` flag is now available in the `Args` struct and is propagated through various command executions.
Updated the schema store options to include a no_cache flag and removed the default cache TTL setting. This change allows for more flexible caching behavior during formatting and linting operations.
Refactor the cache directory creation to ensure it is created if it does not exist, simplifying the logic and improving error handling.
Enhance the get_cache_file_path function to accept a no_cache parameter, allowing callers to bypass cache retrieval. Update SchemaStore to utilize the new option for catalog and schema cache paths.
- Added tombi-cache as a dependency.
- Introduced Options struct for cache configuration.
- Updated get_cache_file_path and read_from_cache functions to utilize the new caching options.
- Refactored schema store to support caching options.
- 新しいエラータイプ `CacheDirectoryRemoveFailed` を `error.rs` に追加。
- `refresh_cache` 関数を `lib.rs` に実装し、キャッシュディレクトリの内容を削除する機能を追加。
- `Backend` に `refresh_cache` メソッドを追加し、LSP コマンドとして利用可能に。
- VSCode 拡張機能にキャッシュリフレッシュコマンドを追加。
- テストを追加してキャッシュリフレッシュ機能の動作を確認。
@ya7010 ya7010 merged commit e40cb63 into main Jul 4, 2025
6 checks passed
@ya7010 ya7010 deleted the feat_support_schema_cache branch July 4, 2025 17:58
@ya7010 ya7010 added the enhancement New feature or request label Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0