Skip to content

Collection Query Snapshot changes and just snapshot changes are firing with mixed results #1975

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

Closed
jimmykane opened this issue Dec 16, 2018 · 4 comments

Comments

@jimmykane
Copy link

jimmykane commented Dec 16, 2018

Version info

Angular: 7.1.3

Firebase: 5.7.0

**AngularFire:**5.1.1

Other (e.g. Ionic/Cordova, Node, browser, operating system):

How to reproduce these conditions

Failing test unit, Plunkr, or JSFiddle demonstrating the problem

No plunker possible

Steps to set up and reproduce

  1. In my service I have a call to a collection query by multiple where clauses and return back a single observable.
public getStreams(eventID: string, activityID: string, types: string[]): Observable<StreamInterface[]> {
    return combineLatest.apply(this, types.map((type) => {
      return this.afs
        .collection('events')
        .doc(eventID)
        .collection('activities')
        .doc(activityID)
        .collection('streams', ref => ref.where('type', '==', type))
        .snapshotChanges()
        .pipe(map((streamSnapshots) => { // @todo should be reduce
          return this.processStreamSnapshots(streamSnapshots)[0] // Get the first element of the return
        }))                                                      // since the return with equality on the query should only fetch one afaik in my model
    })).pipe(map((streams: StreamInterface[]) => {
      return streams.filter((stream) => !!stream)
    }))
  1. Then I have some other call that fetches everything from that collection
public getAllStreams(eventID: string, activityID: string): Observable<StreamInterface[]> {
    return this.afs
      .collection('events')
      .doc(eventID)
      .collection('activities')
      .doc(activityID)
      .collection('streams')
      .snapshotChanges()
      .pipe(map((streamSnapshots) => {
        debugger;
        return this.processStreamSnapshots(streamSnapshots);
      }))
  }

I am calling and subscribing first on the multiple where query of my service eg:

this.streamsSubscriptions.push(this.eventService.getStreams(this.event.getID(), activity.getID(), [DataLatitudeDegrees.type, DataLongitudeDegrees.type])

Than at some point later I subscribe also to the "all" list

this.eventService.getAllStreams(this.event.getID(), activity.getID());

However the 'all' call gets triggered 2 times.
One it returns the results of the:

this.streamsSubscriptions.push(this.eventService.getStreams(this.event.getID(), activity.getID(), [DataLatitudeDegrees.type, DataLongitudeDegrees.type])

... which in my logic is an array of 2

And the second time it returns as expected all the results. (Array of lets say 20)

What am I missing or is this a bug

I would expect only one call with just all the results

Sample data and security rules

No data

Debug output

** Errors in the JavaScript console **

** Output from firebase.database().enableLogging(true); **

** Screenshots **

Expected behavior

See description

Actual behavior

See description

@jek-bao-choo
Copy link
Contributor

same here. experiencing this problem.

@phihochzwei
Copy link

We are facing the exact same problem here. Anyone a solution for this?

@jimmykane
Copy link
Author

See

public getAllStreams(user: User, eventID: string, activityID: string): Observable<StreamInterface[]> {
    return this.afs
      .collection('users')
      .doc(user.uid)
      .collection('events')
      .doc(eventID)
      .collection('activities')
      .doc(activityID)
      .collection('streams')
      .get() // @todo replace with snapshot changes I suppose when @https://github.com/angular/angularfire2/issues/1552 is fixed
      .pipe(map((querySnapshot) => {
        return querySnapshot.docs.map(queryDocumentSnapshot => this.processStreamQueryDocumentSnapshot(queryDocumentSnapshot))
      }))
  }

The comment there on the above block.

In short use get to ensure

@jamesdaniels
Copy link
Member

I'm not exactly clear what this issue is? Does it remain or is this outdated. Closing for now but will reopen if still exists.

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

No branches or pull requests

4 participants