参拝の解析処理の高速化とログイン切れの修正#113
Merged
Merged
Conversation
永続化された古いIDトークン(発行から1時間で失効)をそのまま送っていたため、 失効後の参拝でFunctionsのverifyIdTokenが403を返し即ログアウトしていた。 送信直前に onAuthStateChanged で認証状態の確定を待ってから getIdToken() で 最新トークンを取得する(失効時はSDKが自動リフレッシュ)ことで根本解決する。 index.vueは a6da64e で対応済みだったが sanpai.vue が直し漏れていた。 Co-authored-by: kojira <kojira@users.noreply.github.com>
参拝のたびに get_activity_list で github_activities を全件読み出し、 user_performance で全件を再ソート・再集計していたため、参拝履歴が増える ほど Firestore 読み取り件数と計算量が線形に増加していた。 user_performance の各寄与は加算的で、唯一のクロスバッチ依存はバッチ境界 (前回最終イベントと今回先頭イベントの時間差)のみ。hp は continuous_count*2 が 「diff<=7200秒のペア数*2」と等価であることを利用し、保存済み status と 新着分のみで全件計算と同一結果を再現する compute_performance_increment を新設。 user_performance 自体は status/userOGP でも使うため変更せず、初回(status または last_activity_created_at 未保存)は従来通り全件計算で基準を初期化する。 全件計算と増分計算の一致は2分割5000試行+3バッチ3000試行で確認済み。 Co-authored-by: kojira <kojira@users.noreply.github.com>
actionlint が "the runner of ... action is too old to run" を検出し actions-test ジョブが失敗していた(alpha-0.2 既存の不具合)。 ランタイム廃止された古いアクションを互換性のある最新メジャーへ更新する。 - actions/checkout@v3 -> v4 - actions/setup-node@v2,v3 -> v4 - actions/cache@v3 -> v4 - google-github-actions/auth@v1 -> v2 - google-github-actions/setup-gcloud@v1 -> v2 入力仕様は各アクションで互換のため挙動は変えない。 ローカルで actionlint v1.7.12 がエラーなし(exit 0)を確認済み。 Co-authored-by: kojira <kojira@users.noreply.github.com>
ユニットテスト可能にするため、副作用のない純粋な計算ロジック (user_performance / user_formatted_performance / compute_performance_increment / raw_user_data_from_status / latest_activity_created_at / get_level など)を index.js から performance.js へ抽出し、index.js からは require して使用する。 関数本体は逐語移設で挙動は不変。エミュレータで全関数のロードを確認済み。 Co-authored-by: kojira <kojira@users.noreply.github.com>
node:test/node:assert を使用(追加依存なし)。npm test で実行可能。 - 各イベント種別の加点、時間差による agility/hp、レベル算出などの単体検証 - IssuesEvent が payload 文字列時のみ加点する既存挙動も明示的に検証 - 全件計算 vs 増分計算の一致をランダム多数試行(2分割2000+3バッチ1000)で検証 全12テストがパスすることを確認済み。 Co-authored-by: kojira <kojira@users.noreply.github.com>
push 時に app/functions の npm test(node --test)を実行する専用ジョブを setup.yml に追加し、参拝解析のユニット/等価性テストを CI で自動検証する。 Node 18(CIと同一)で node --test がテストを自動検出し全件パスすることを確認済み。 Co-authored-by: kojira <kojira@users.noreply.github.com>
レビュー指摘対応: - #2 暗黙のグローバル変数(level/previousItem/continuous_count/previous_time/ current_time/diff)を let 宣言に修正。挙動は不変(各関数先頭で初期化されるため)。 - #1 compute_performance_increment が全件計算と一致する前提(新着は累積済みより後)を doc コメントで明文化し、前提が崩れた場合に console.warn で検知するガードを追加。 呼び出し側(sanpai)にも前提を満たす旨のコメントを追記。 - ガードが機能することのテストを追加(全13テスト pass)。 Co-authored-by: kojira <kojira@users.noreply.github.com>
レビュー指摘#4対応。トークンは送信直前に getIdToken() で取得したローカル変数を 使うようになり、mapGetters の token は未使用になったため削除。Nuxt ビルドで検証済み。 Co-authored-by: kojira <kojira@users.noreply.github.com>
レビュー指摘#5対応。テストは performance.js(moment のみ依存)を検証するもので、 canvas 等のネイティブビルド(OGP生成専用)は不要。--ignore-scripts により CI のテストジョブを高速化し、ネイティブビルド失敗の影響を受けないようにする。 Co-authored-by: kojira <kojira@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
「参拝時の表示が遅い」「GitHubログインがすぐ切れる」という2つの課題に対し、根本原因を特定して修正します。あわせて解析ロジックのテスト追加、CI(
actionlint)修正、レビュー指摘対応を含みます。対象:
alpha-0.2ブランチ(env/prodと実質同一コード)課題と原因
1. ログインがすぐ切れる
web/pages/sanpai.vueが localStorage に永続化した古いトークンをそのまま送り、失効後の参拝で 403 → 即ログアウトしていた(index.vueはa6da64eで対応済みだったがsanpai.vueが直し漏れ)。2. 参拝の解析処理が遅い
sanpaiが参拝のたびにgithub_activitiesを全件読み出し&user_performanceで全件再集計しており、履歴が増えるほど線形に重くなっていた(キャッシュ未活用)。変更内容(コミット単位)
fix(web):sanpai.vueでonAuthStateChanged後にgetIdToken()で最新トークンを取得(失効時はSDK自動リフレッシュ)。マウント直後の誤ログアウトも防止。perf(functions): 保存済み status と新着分のみで計算するcompute_performance_incrementを新設し、全件読み出し・全件再集計を廃止。user_performanceはstatus/userOGPでも使うため変更せず、初回は全件計算で基準を初期化。ci:actionlintが弾く古いアクションを互換最新メジャーへ更新。refactor(functions): 計算ロジックをapp/functions/performance.jsに分離(逐語移設・挙動不変)。test(functions):node:test(追加依存なし)でユニット+等価性テストを追加。npm testで実行可。ci:npm testを実行するtestジョブを追加(--ignore-scriptsでcanvasビルド不要・高速)。レビュー指摘対応(追加コミット)
compute_performance_incrementの不変条件(新着は累積分より後)を doc 明文化+崩れた場合のconsole.warnガード追加、検知テスト追加。performance.jsの暗黙グローバル変数をlet宣言化(挙動不変)。sanpai.vueの未使用tokengetter を削除。testジョブをnpm install --ignore-scriptsに変更。検証
app/functions/test/performance.test.js全13テスト pass(CI上でも実行・確認、Node18でも自動検出)。IssuesEventの payload バグ挙動の固定、増分計算の不変条件ガード。sanpai含む全関数ロード成功(リファクタ後も確認)。pages/sanpai正常コンパイル。actions-test/build/testすべて pass。検証環境の補足
firebase-toolsを直接導入してエミュレータ起動。canvas@2.8.0は Node22 でビルド不可(OGP生成専用)のため、検証時のみローカルでcanvas@3.1.0使用(package.json未変更・コミットなし)。get_feedが GitHub 実API依存で不安定なため、核心ロジックを上記テストで厳密検証。関連 / 補足