Skip to content

TTSキャッシュをパージするスクリプトを実装#5302

Merged
TinyKitten merged 3 commits intodevfrom
feature/purge-tts-cache
Feb 17, 2026
Merged

TTSキャッシュをパージするスクリプトを実装#5302
TinyKitten merged 3 commits intodevfrom
feature/purge-tts-cache

Conversation

@TinyKitten
Copy link
Copy Markdown
Member

@TinyKitten TinyKitten commented Feb 17, 2026

Summary by CodeRabbit

  • 新機能

    • TTSキャッシュの検索・照合・削除を行うCLIツールを追加し、ストレージ上の孤立ファイル検出と確認削除が可能になりました。
  • チア(保守作業)

    • TypeScriptベースCLIを実行するためのスクリプトと実行サポートを追加しました(開発用実行ツールを導入)。
    • ビルド設定を更新してCLIコードをビルド対象から除外しました。

@TinyKitten TinyKitten self-assigned this Feb 17, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 17, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Firestore の TTS キャッシュ(caches/tts/voices)と Cloud Storage の MP3 を照合・検索・(確認付きで)削除する TypeScript CLI を 2 本追加し、npm スクリプトと devDependency に tsx を追加、CLI ソースをビルド除外にしました。

Changes

Cohort / File(s) Summary
TTS キャッシュ管理 CLI
functions/src/cli/find-tts-cache.ts, functions/src/cli/find-orphaned-tts.ts
新規 CLI ツール。引数パース、Firebase Admin 初期化、Firestore の caches/tts/voices 列挙、Cloud Storage の MP3 列挙、差分検出、結果表示、オプションで削除(確認プロンプト・個別エラーハンドリング)。
npm スクリプト & 依存 / ビルド設定
functions/package.json, functions/tsconfig.build.json
find-tts-cache/find-orphaned-tts 用の npm スクリプト(dev/prod variants)を追加し、tsx を devDependency に追加。tsconfig.build.jsonsrc/cli/** を除外追加。

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant CLI as CLI\n(find-tts-cache / find-orphaned-tts)
    participant Admin as Firebase Admin
    participant FS as Firestore
    participant GS as Cloud Storage

    User->>CLI: 起動 (args: bucket, project, options)
    CLI->>Admin: 初期化 (projectId, bucket)
    Admin->>FS: Firestore クライアント取得
    Admin->>GS: Storage クライアント取得
    CLI->>FS: `caches/tts/voices` を一覧取得
    CLI->>GS: `caches/tts/...` をページネーションで列挙
    CLI->>CLI: Firestore/Storage の差分計算(検出 / マッチ)
    CLI->>User: 結果表示(候補一覧、オーファン一覧)
    alt --delete フラグ
        CLI->>User: 削除確認プロンプト
        User->>CLI: 確認応答
        CLI->>FS: ドキュメント削除(該当)
        CLI->>GS: MP3 ファイル削除(該当)
        CLI->>User: 削除結果報告
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ストアレビュー通知実装 #4497 — 同じ functions/package.jsonfunctions/tsconfig.build.json を変更しており、スクリプト/ビルド除外の追加が重複または関連する可能性あり。

Poem

🐰 ぴょんと来たよ、新しい CLI
キャッシュの森をちょこちょこ探して
Firestore と Storage をつなぎ合せて
「消す?」って聞いて、そっと片付けるよ
✨ コードの畑でぴょんぴょんお祝い!

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (7 files):

⚔️ functions/package-lock.json (content)
⚔️ functions/package.json (content)
⚔️ functions/src/funcs/tts.ts (content)
⚔️ functions/tsconfig.build.json (content)
⚔️ src/hooks/useHeaderStateText.ts (content)
⚔️ src/hooks/useTTS.test.ts (content)
⚔️ src/hooks/useTTS.ts (content)

These conflicts must be resolved before merging into dev.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは「TTSキャッシュをパージするスクリプトを実装」で、追加されたfind-tts-cache.tsとfind-orphaned-tts.tsという2つのTTSキャッシュ管理スクリプトの実装内容と一致しており、変更の主要な目的を明確に要約しています。

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/purge-tts-cache
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch feature/purge-tts-cache
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

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

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@functions/src/cli/find-tts-cache.ts`:
- Around line 150-189: The printed ID and the storage/delete paths currently use
data.id which can be missing or inconsistent; switch to using the Firestore
document id (doc.id) everywhere. In the for-loops that iterate results (where
you have const data = doc.data()), replace references to data.id (the console
log "ID: ..." and the id binding const id: string = data.id and any
storagePathJa/storagePathEn construction) with doc.id (assign const id: string =
doc.id) so display and deletion use the document key consistently.

Comment thread functions/src/cli/find-tts-cache.ts
Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@functions/src/cli/find-tts-cache.ts`:
- Around line 185-207: The current loop always logs "削除完了" after attempting
deletions even when some deleteResults are rejected; update the logic in the
block handling results (variables: results, deleteResults, labels,
storagePathJa/storagePathEn, doc.ref.delete()) to detect if any Promise in
deleteResults has status 'rejected' and only print a success message for that id
when all succeeded; otherwise print a failure/partial-failure message (including
the per-label warnings already produced) and avoid the misleading "削除完了" line or
change it to "削除完了(部分失敗)" when some deletions failed.
- Around line 32-80: In parseArgs, safeguard all options that consume the next
argv element (notably the --field, --bucket, and --project handling inside the
for loop) by verifying the next token exists and is not another flag (e.g.,
startsWith('--')) before assigning it; if the value is missing or looks like a
flag, print a clear error and process.exit(1). Update the switch cases for
'--field', '--bucket', and '--project' to check const value = args[++i]; if
(!value || value.startsWith('--')) { console.error(...); process.exit(1); }
(preserve the existing validation for 'ssmlJa'/'ssmlEn' in --field).
- Around line 226-231: The current main().catch(...).finally(...) pattern can
overwrite the error exit code; remove the .finally(() => process.exit(0)) and
instead set process.exitCode = 1 inside the catch handler (and avoid calling
process.exit synchronously in catch). Update the catch on main() to log the
error (using err.message) and assign process.exitCode = 1, leaving process
termination to Node.js so cleanups run; ensure no other code calls
process.exit(0) unconditionally after main().

Comment thread functions/src/cli/find-tts-cache.ts
Comment thread functions/src/cli/find-tts-cache.ts Outdated
Comment thread functions/src/cli/find-tts-cache.ts Outdated
@TinyKitten TinyKitten merged commit e7c4c06 into dev Feb 17, 2026
4 checks passed
@TinyKitten TinyKitten deleted the feature/purge-tts-cache branch February 17, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant