Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix remove badge code #624

Merged
merged 7 commits into from
Jun 21, 2022
Merged

Bugfix remove badge code #624

merged 7 commits into from
Jun 21, 2022

Conversation

bannzai
Copy link
Owner

@bannzai bannzai commented Jun 19, 2022

Abstract

バッジを消している関数が過度に共通化されていたのでバラした

Why

元々はバッジが消えないという問い合わせからの調査だったが、手元で再現しないのと問い合わせのログを見てもいまいちわからなかったのでリファクタリングする程度にとどめた

Links

close: #625
これは不要

Checked

  • Analyticsのログを入れたか
  • 境界値に対してのUnitTestを書いた
  • パターン分岐が発生するWidgetに対してWidgetTestを書いた
  • リリースノートを追加した

@bannzai bannzai mentioned this pull request Jun 19, 2022
4 tasks
@bannzai bannzai force-pushed the bugfix/function/remove-badge branch from 4b832e5 to 871c318 Compare June 19, 2022 22:24
@bannzai
Copy link
Owner Author

bannzai commented Jun 21, 2022

根本的な原因はbatch.commitを待ってremoveBadgeをしていたが、それだとUIが更新(オフラインDBの更新時)された後にbatch.commit経由でのオンラインDBの更新を待っている間にラグがあり、ユーザーは 書き込みは終わったがバッジが消えない と認識したため問い合わせが発生していたもよう

  • オフラインキャッシュが有効の場合は、DBのデータのアップデートが完了する前にSnapShotListenerのイベントが更新される。厳密にはオフラインのデータの更新が完了した時点でSnapShotListenerのイベントも更新される。また、その後にオンラインのデータが更新された後にもSnapShotListnerのイベントが更新される
    • SnapShotのMetadataに Local or Server が更新されたかを判断できるプロパティが生えているので必要ならばこれを使う
      • https://firebase.google.com/docs/firestore/query-data/listen
      • Retrieved documents have a metadata.hasPendingWrites property that indicates whether the document has local changes that haven't been written to the backend yet. You can use this property to determine the source of events received by your snapshot listener:
    • ただ、database.set(data, {merge: true}) を awaitしているときに、実際にsuspendを終えるのはオンラインデータの書き込みが終了した時。なので、オフラインのデータ更新 → SnapShotListenerが実行される → UIの更新 → オンラインデータの更新 → UIの更新 という順序を辿ることがある。困るのがオフラインのデータの更新の後にUIが更新されるとユーザーが処理完了したと認識してしまうところ
  • WriteBatch#commit の書き込みが遅い
    • 複数のドキュメントのbatch write が数秒かかることがある。すぐ終わることもある
    • これによりawait database.set(data, { merge: true }) で await していると後続の処理が実行されるのが遅れる。例えばSnackBarの表示やバッジを消す処理

@bannzai bannzai marked this pull request as ready for review June 21, 2022 21:21
@bannzai bannzai merged commit 550816d into main Jun 21, 2022
@bannzai bannzai deleted the bugfix/function/remove-badge branch June 21, 2022 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant