Skip to content

Comments

perf: cache with precomputed etag#2949

Open
ras0q wants to merge 3 commits intomasterfrom
perf/cache-with-etag
Open

perf: cache with precomputed etag#2949
ras0q wants to merge 3 commits intomasterfrom
perf/cache-with-etag

Conversation

@ras0q
Copy link
Member

@ras0q ras0q commented Feb 19, 2026

fixes #2948

実装内容

  • utils/etag package を追加し etag.Entity[T any] を実装
  • 事前計算したETagを返すようにする
    • prettyのときはそこまで速度が求められないと思うのでETagを活用しない

比較

  • unicode: 1738
  • original: 1

Before

304が返っているリクエストもETagの計算がボトルネックになってあまり高速化していない

image

After

特にキャッシュなしでのレスポンスが遅くサイズが大きいunicodeで改善
originalは数が少ないので304でも200と±20msくらいしか変わらなそう

image

Summary by CodeRabbit

  • New Features

    • スタンプデータにETag対応を導入し、APIでETag付きレスポンスを返せるようになりました。
    • 事前計算済みETagを利用するレスポンス処理を追加しました。
  • Refactor

    • スタンプ取得の内部処理をETagラップに合わせて更新しました。
  • Tests

    • スタンプ関連テストをETagラッパーを扱う形に修正しました。

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch perf/cache-with-etag

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Note

Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
repository/gorm/stamp_test.go (1)

249-263: ⚠️ Potential issue | 🟠 Major

assert.LenEntity ではなく Value() に対して実行してください。

GetAllStampsWithThumbnail の戻り値が *etag.Entity に変わったため、assert.Len(arr, n*2) は長さ判定に失敗します。両テストで arr.Value() を使う必要があります。

🩹 修正案
-		assert.Len(arr, n*2)
+		assert.Len(arr.Value(), n*2)
@@
-		assert.Len(arr, n*2)
+		assert.Len(arr.Value(), n*2)

Also applies to: 264-277

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@repository/gorm/stamp_test.go` around lines 249 - 263, The failing length
assertions call assert.Len on the etag.Entity pointer returned by
repo.GetAllStampsWithThumbnail; update the tests to call .Value() when checking
lengths (e.g., replace assert.Len(arr, n*2) with assert.Len(arr.Value(), n*2))
in the test block that uses repo.GetAllStampsWithThumbnail and the adjacent
similar test (both places where arr is used), ensuring any other assertions
referencing arr for length use arr.Value().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@repository/gorm/stamp_test.go`:
- Around line 249-263: The failing length assertions call assert.Len on the
etag.Entity pointer returned by repo.GetAllStampsWithThumbnail; update the tests
to call .Value() when checking lengths (e.g., replace assert.Len(arr, n*2) with
assert.Len(arr.Value(), n*2)) in the test block that uses
repo.GetAllStampsWithThumbnail and the adjacent similar test (both places where
arr is used), ensuring any other assertions referencing arr for length use
arr.Value().

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Request timed out after 900000ms (requestId=d4ab6312-1585-409b-89f9-810f2c4bfd9d)

@ras0q ras0q marked this pull request as draft February 19, 2026 14:40
@ras0q ras0q marked this pull request as ready for review February 19, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

GET /stamps がキャッシュが効いていても遅い

1 participant