Skip to content

fix(task-results): skip getAnswers full-scan for anonymous users#3677

Merged
KATO-Hiro merged 3 commits into
stagingfrom
fix/skip-getanswers-for-anonymous
Jun 16, 2026
Merged

fix(task-results): skip getAnswers full-scan for anonymous users#3677
KATO-Hiro merged 3 commits into
stagingfrom
fix/skip-getanswers-for-anonymous

Conversation

@KATO-Hiro

@KATO-Hiro KATO-Hiro commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

getAnswers(undefined) drops the WHERE filter and full-scans taskAnswer. Guard the call in createTaskResults / getTaskResultsOnlyResultExists so anonymous users skip the DB round-trip, and make userId types honest (string | undefined), including TaskResult.user_id.

Summary by CodeRabbit

リリースノート

  • 新機能

    • ログインなし(未ログイン)の状態でも、タスク結果の取得・表示が可能になりました。
    • タグ条件でのタスク結果取得にも対応し、未挑戦のタスクはデフォルト表示されます。
  • テスト

    • 未ログイン時に回答情報を参照しない挙動や、返却結果の内容を検証するテストを追加しました。

getAnswers(undefined) drops the WHERE filter and full-scans taskAnswer.
Guard the call in createTaskResults / getTaskResultsOnlyResultExists so
anonymous users skip the DB round-trip, and make userId types honest
(string | undefined), including TaskResult.user_id.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6f0a4302-78a4-422d-8295-715df389d5b2

📥 Commits

Reviewing files that changed from the base of the PR and between e482684 and 10e8a04.

📒 Files selected for processing (1)
  • src/lib/types/task.ts

📝 Walkthrough

Walkthrough

TaskResult.user_id の型を string | undefined に変更し、サービス層の複数の公開 API(getTaskResults ほか)で userId 引数を拡張。匿名時は DB アクセスをスキップして空 Map で結果生成。対応テストも追加。

Changes

匿名ユーザー対応:タスク結果サービス

Layer / File(s) Summary
TaskResult 型定義変更
src/lib/types/task.ts
TaskResult.user_id を `string
サービス API と匿名分岐実装
src/lib/services/task_results.ts
getTaskResultsgetTaskResultsOnlyResultExistsgetTasksWithTagIdscreateDefaultTaskResultmergeTaskAndAnsweruserIdstring | undefined に拡張。userIdundefined の場合に getAnswers DB アクセスをスキップして空 Map を使用する分岐を実装。
匿名ケーステスト
src/test/lib/services/task_results.test.ts
getTaskResultsgetTaskResultsOnlyResultExists に対して userId = undefined 時に getAnswers が呼ばれない、全タスクがデフォルト返却・空配列返却されることを検証するテストを追加。

Sequence Diagram

sequenceDiagram
  participant Client
  participant getTaskResults
  participant createTaskResults
  participant answer_crud
  participant mergeTaskAndAnswer

  Client->>getTaskResults: getTaskResults(undefined)
  getTaskResults->>createTaskResults: userId = undefined
  alt userId === undefined
    createTaskResults->>createTaskResults: 空Mapを作成
  else userId存在
    createTaskResults->>answer_crud: getAnswers(userId)
    answer_crud-->>createTaskResults: 回答Map返却
  end
  createTaskResults->>mergeTaskAndAnswer: 結果とMapをマージ
  mergeTaskAndAnswer-->>getTaskResults: TaskResult[]
  getTaskResults-->>Client: 返却
Loading

🎯 2 (Simple) | ⏱️ ~10 分

Possibly related issues

  • #3676: このPRで実装した変更(userIdstring | undefined に変更し、getAnswers 呼び出しを匿名時スキップ)は issue #3676 が要求する内容と完全に一致。

Poem

🔓 ログインなくても旅はできる、
undefined を抱えて進む勇気、
getAnswers は呼ばれず静かに空へ、
匿名の足跡、デフォルトで刻む、
型の海に | undefined が咲いた 🌸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは、匿名ユーザーに対する getAnswers のフルスキャン回避という PR の主要な目的を正確に反映しており、変更内容の核となるパフォーマンス改善が明確に示されている。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/skip-getanswers-for-anonymous

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

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

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@KATO-Hiro

KATO-Hiro commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/types/task.ts`:
- Around line 64-67: The TaskResult interface is missing TSDoc documentation,
which makes the public contract unclear to consumers, especially regarding the
user_id field that can be undefined for anonymous (logged-out) results. Add a
comprehensive TSDoc block to the TaskResult interface that documents what the
type represents and explicitly clarifies that user_id is optional and undefined
for anonymous results. Follow the src/**/*types/** coding guideline that
requires TSDoc on all exported types.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1c42bbdd-38bb-495a-9140-6f34ba91ec29

📥 Commits

Reviewing files that changed from the base of the PR and between 86ef295 and e482684.

📒 Files selected for processing (3)
  • src/lib/services/task_results.ts
  • src/lib/types/task.ts
  • src/test/lib/services/task_results.test.ts

Comment thread src/lib/types/task.ts
…antics

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@KATO-Hiro KATO-Hiro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

LGTM

@KATO-Hiro KATO-Hiro merged commit 6a4a881 into staging Jun 16, 2026
3 checks passed
@KATO-Hiro KATO-Hiro deleted the fix/skip-getanswers-for-anonymous branch June 16, 2026 23:14
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