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

collectionChanges is firing for every element on a single deletion #75

Open
m-dierker opened this issue Jul 21, 2023 · 3 comments · May be fixed by #99
Open

collectionChanges is firing for every element on a single deletion #75

m-dierker opened this issue Jul 21, 2023 · 3 comments · May be fixed by #99
Assignees

Comments

@m-dierker
Copy link

I have AngularFire/RxFire code similar to the following:

collectionChanges(
    collection(this.firestore, "col1/doc1/col2"))
.subscribe(changes => {
  console.log('RxFire changes', changes);
});

This generally works: When the page loads, I get added events for every document in the collection. When a document changes, a single modified event fires. However, when a document is deleted, the next change batch includes a removed event (good) and also a modified event for every other element in the collection (bad). 🤔

Any idea why these extra modify events are happening + how to avoid all the extra reads? or is this all from the cache?

I've verified there's no actual change to the other documents in the collection. A single modified change mentions oldIndex and newIndex so I wonder if it's maybe trying to update the index of every element, but there isn't a sort order so any index is undefined anyways.


If it's helpful, as a test I tried the equivalent Firebase code:

const q = query(collection(this.firestore, "collection1/doc1/collection2"));

onSnapshot(q, (snapshot) => {
  const docs = snapshot.docChanges();
  console.log("Changes received", docs);
});

This works as expected and only fires one removed event, which is why I think the bug is in RxFire.

@m-dierker
Copy link
Author

m-dierker commented Jul 21, 2023

rxfire ^6.0.0 and @angular/fire ^7.4.1 were my original library versions if helpful. I just updated to rxfire 6.0.3 and verified this still happens.

@davideast davideast self-assigned this Aug 1, 2023
@davideast
Copy link
Collaborator

@m-dierker Apologies on the delay here! I believe this is because collectionChanges() was updated sometime ago with the includeMetadataChanges option. This changes the behavior significantly because it accounts for metadata changes within the cache. The Firebase code you provided isn't exactly equivalent because you'd need to include that configuration as well. It also appears that the function was update with some custom code to surface the changes within documents. I didn't make these changes so I'll have to do some testing and see how we should handle this in the upcoming version as it would be a breaking change to modify it at this point.

@blackholegalaxy
Copy link

blackholegalaxy commented Mar 24, 2024

Any news about this @davideast ? With current SDK version, current version of @angular/fire, collectionChanges observable ticks multiple times on deletion (one updated event and one removed).

Could the includeMetadataChanges: true be modifiable by passing a different value through collectioChanges option argument (defaulting to true if needed).

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 a pull request may close this issue.

3 participants