-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
…support_schema_cache
There was a problem hiding this 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
andtombi-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 aResult<Option<T>, E>
; consider unwrapping theResult
first and then handling theOption
withmatch
orand_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()
onResult<Option<DocumentSchema>, Error>
will not compile; you need to handle theResult
andOption
separately (e.g.,let res = self.fetch_document_schema(...).await?; if let Some(schema) = res { ... }
).
match self.fetch_document_schema(schema_url).await.transpose() {
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 拡張機能にキャッシュリフレッシュコマンドを追加。 - テストを追加してキャッシュリフレッシュ機能の動作を確認。
Support #624