dappsnation / akita-ng-fire

Akita ❤️ Angular 🔥 Firebase
MIT License
131 stars 27 forks source link

syncCollection is syncing too many docs #182

Closed randallmeeker closed 3 years ago

randallmeeker commented 3 years ago

Trying to figure out the best way to troubleshoot this issue.

I have a store called accessLogs. You can see my setup below.

I sync the store with a filter. The initial documents from that sync show the correct records properly filtered, however, records that come in after the initial load will be outside the scope of the query. To repeat in a different way. The store is filled with records where doc.projectId === params.projectId, but after that first load, future records do not respect this filter.

   // first I clear the store and then I sync the records I want.
    params$
      .pipe(
        untilDestroyed(this),
        tap(() => this.accessLogStore.reset()),
        switchMap((params) =>
          this.accessLogsService.syncCollection(
            (ref) => {
              let query:
                | firebase.firestore.CollectionReference
                | firebase.firestore.Query = ref
                .orderBy('scannedAt', 'desc')
                .limit(100)
                .where('projectId', '==', params.projectId);
              return query;
            },
            {
              reset: true,
            }
          )
        )
      )
      .subscribe();

    this.accessLogQuery
      .selectAll()
      .pipe(untilDestroyed(this))
      .subscribe((logs) => {
        this.lastUpdate = logs[0]
          ? logs[0].createdAt.seconds * 1000
          : Date.now();
        this.dataSource = logs;
      });
randallmeeker commented 3 years ago

closing this issue. I wrote it too early. My apologies. I was untilDestroyed too early. Bad RXJS.

fritzschoff commented 3 years ago

:)