Skip to content

Update ChatViewController.swift#3

Open
carizmian wants to merge 1 commit intoappbrewery:masterfrom
carizmian:master
Open

Update ChatViewController.swift#3
carizmian wants to merge 1 commit intoappbrewery:masterfrom
carizmian:master

Conversation

@carizmian
Copy link
Copy Markdown

@carizmian carizmian commented May 13, 2020

An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot.
So instead of querySnapshot?.documents I've used: querySnapshot?.documentChanges
And instead of doc.data() I've used doc.document.
It's more efficient because you don't load all of the messages to the Message every time you pull your messages from firestore.
First time it gets all of the messages and the next times it gets only messages which changed.
So, messages = [], should be used before pulling all database.

You can listen to a document with the onSnapshot() method. An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot. 
So instead of querySnapshot?.documents I've used: querySnapshot?.documentChanges 
And instead of doc.data() I've used doc.document.
It's more efficient because you don't load all of the messages to the Message every time you pull your messages from firestore. 
First time it gets all of the messages and the next times it gets only messages which changed.
So, messages = [], should be used before pulling all database.
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.

2 participants