機能追加: スナップショットリスナーに差分更新機能を追加 - #68
Merged
Merged
Conversation
Firestoreのスナップショットリスナーで、コレクション全体ではなく 変更されたドキュメントのみを受け取れる新しいAPIを追加しました。 追加した型: - FirestoreDocumentChangeType: 変更タイプ (added/modified/removed) - FirestoreDocumentChange<Model>: 変更情報を格納するstruct 追加したメソッド: - listenChanges(): Collection用差分リスナー - listenChanges(parent:superParent:...): SubCollection用差分リスナー - listenCollectionGroupChanges(): CollectionGroup用差分リスナー 既存のlisten()メソッドは変更なく、後方互換性を維持しています。
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.
概要
Firestoreのスナップショットリスナーで、コレクション全体ではなく変更されたドキュメントのみを受け取れる新しいAPIを追加しました。
背景
現在の
listen()メソッドはsnapshots.documentsを使用して全ドキュメントを返却しており、1件の変更でもコレクション全体の処理が走る非効率な実装になっていました。Firebase SDKの
documentChangesAPIを活用することで、差分のみを返却できるようになります。主な変更内容
追加した型
FirestoreDocumentChangeType: 変更タイプを表すenum (added/modified/removed)FirestoreDocumentChange<Model>: 変更情報を格納するstruct追加したメソッド
listenChanges(filter:includeCache:order:limit:)listenChanges(parent:superParent:filter:includeCache:order:limit:)listenCollectionGroupChanges(collectionName:filter:includeCache:order:limit:)使用例
後方互換性
既存の
listen()メソッドは変更なく、後方互換性を維持しています。テスト
xcrun swift buildでビルド成功を確認レビューポイント
FirestoreDocumentChangeType,FirestoreDocumentChange)の設計mapDocumentChangesヘルパーメソッドの実装