@@ -24,9 +24,9 @@ import {
2424} from '@angular/fire/auth' ;
2525import { getApp } from '@angular/fire/app' ;
2626import { MatSnackBar } from '@angular/material/snack-bar' ;
27-
27+ import { retryBackoff } from 'backoff-rxjs' ;
2828import { switchMap , tap , take , catchError } from 'rxjs/operators' ;
29- import { Observable , of , Subject } from 'rxjs' ;
29+ import { Observable , of , defer , Subject } from 'rxjs' ;
3030import {
3131 doc ,
3232 Firestore ,
@@ -35,6 +35,7 @@ import {
3535 deleteDoc ,
3636 collectionData ,
3737 collectionCount ,
38+ getCountFromServer ,
3839 query ,
3940 orderBy ,
4041 Timestamp ,
@@ -176,10 +177,15 @@ export class TaskService {
176177 where ( 'priority' , '!=' , 'null' ) ,
177178 orderBy ( 'createdTime' , 'desc' )
178179 ) ;
179- return this . loadTaskCount ( ) . pipe (
180- take ( 1 ) ,
180+ return defer ( ( ) => this . loadTaskCount ( ) ) . pipe (
181+ retryBackoff ( {
182+ initialInterval : 500 ,
183+ maxInterval : 2000 ,
184+ maxRetries : 10 ,
185+ }
186+ ) ,
181187 switchMap ( ( taskCount ) => {
182- if ( taskCount === 0 ) {
188+ if ( taskCount . data ( ) . count === 0 ) {
183189 return of ( [ ] as Task [ ] ) ;
184190 }
185191 return collectionData ( taskQuery , { idField : 'id' } ) as Observable <
@@ -193,12 +199,12 @@ export class TaskService {
193199 ) ;
194200 }
195201
196- loadTaskCount ( ) : Observable < number > {
202+ loadTaskCount ( ) {
197203 const taskQuery = query (
198204 collection ( this . firestore , 'todos' ) ,
199205 where ( 'priority' , '!=' , 'null' )
200206 ) ;
201- return collectionCount ( taskQuery ) ;
207+ return getCountFromServer ( taskQuery ) ;
202208 }
203209
204210 loadSubtasks ( maintaskId : string ) : Observable < Task [ ] > {
0 commit comments