Skip to content

Conversation

@ShiinaKin
Copy link
Owner

@ShiinaKin ShiinaKin commented Sep 2, 2025

  • replace Any cache values with ByteArrayContent for type safety
  • implement byte extraction and serialization for ByteArrayContent
  • simplify redis cache serialization/deserialization without gson
  • use lazy initialization for Redis client instance
  • improve cache get retry logic with repeat and early return
  • remove gson imports and related code for cleaner dependencies

… dependency

- replace Any cache values with ByteArrayContent for type safety
- implement byte extraction and serialization for ByteArrayContent
- simplify redis cache serialization/deserialization without gson
- use lazy initialization for Redis client instance
- improve cache get retry logic with repeat and early return
- remove gson imports and related code for cleaner dependencies
@ShiinaKin ShiinaKin requested a review from Copilot September 2, 2025 11:19

This comment was marked as outdated.

@ShiinaKin ShiinaKin changed the title Refactor: simplify response cache data structure to optimize performance Feature: simplify response cache data structure to optimize performance Sep 2, 2025
- add default ContentType.Application.OctetStream on parse failure with warning log
- simplify cache put method by removing unnecessary cast in memory cache provider
@ShiinaKin ShiinaKin requested a review from Copilot September 2, 2025 11:26

This comment was marked as outdated.

@ShiinaKin ShiinaKin requested a review from Copilot September 2, 2025 11:38
Copy link
Contributor

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 simplifies the response cache data structure by replacing generic Any cache values with strongly-typed ByteArrayContent for improved type safety and performance. The implementation removes Gson dependency in favor of native byte array serialization and adds lazy initialization for Redis connections.

  • Replaced Any cache values with ByteArrayContent for type safety
  • Removed Gson dependency and implemented custom byte array serialization/deserialization
  • Added lazy initialization for Redis client and connection instances

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
ui/packages/api-client/src/base.ts Updated BASE_PATH from localhost URL to relative path
gradle/libs.versions.toml Removed Gson library dependency
app/src/main/kotlin/io/sakurasou/hoshizora/plugins/Cache.kt Refactored cache system to use ByteArrayContent, removed Gson, added lazy Redis initialization
app/build.gradle.kts Removed Gson implementation dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 116 to +119
if (expireTime == null) {
provider.saveCache(key, body)
provider.saveCache(key, body as ByteArrayContent)
} else {
provider.saveCache(key, body, expireTime)
provider.saveCache(key, body as ByteArrayContent, expireTime)
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

Unsafe casting of body to ByteArrayContent without type checking. If body is not a ByteArrayContent instance, this will cause a ClassCastException at runtime. Consider using safe casting (body as? ByteArrayContent) or type checking before casting.

Copilot uses AI. Check for mistakes.
Comment on lines 116 to +119
if (expireTime == null) {
provider.saveCache(key, body)
provider.saveCache(key, body as ByteArrayContent)
} else {
provider.saveCache(key, body, expireTime)
provider.saveCache(key, body as ByteArrayContent, expireTime)
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

Unsafe casting of body to ByteArrayContent without type checking. If body is not a ByteArrayContent instance, this will cause a ClassCastException at runtime. Consider using safe casting (body as? ByteArrayContent) or type checking before casting.

Copilot uses AI. Check for mistakes.
@ShiinaKin ShiinaKin merged commit 845c5c4 into main Sep 2, 2025
1 check passed
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.

1 participant