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

manager: smoother fetch items (fixes #7463) #7464

Merged
7 changes: 5 additions & 2 deletions src/app/shared/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Validators } from '@angular/forms';
import { CouchService } from '../shared/couchdb.service';
import { forkJoin, Observable, throwError, of } from 'rxjs';
import { switchMap, map, takeWhile, catchError } from 'rxjs/operators';
import { switchMap, map, takeWhile, catchError, take } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { StateService } from './state.service';
import { TagsService } from './forms/tags.service';
Expand Down Expand Up @@ -136,8 +136,11 @@ export class SyncService {
};
}

// hack: we take the first observable from the array on initialization since we get 2 as opposed to 1
replicatorsArrayWithTags(items, type: 'pull' | 'push', planetField: 'local' | 'parent') {
return this.stateService.getCouchState('tags', planetField).pipe(map(tags => this.createReplicatorsArray(items, type, tags)));
return this.stateService.getCouchState('tags', planetField).pipe(
take(1),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently taking only the first observable in the replicators array.

Could compare the 2 received and then take it only if they are the same.

map(tags => this.createReplicatorsArray(items, type, tags)));
}

createReplicatorsArray(items, type: 'pull' | 'push', allTags: any[] = [], replicators = []) {
Expand Down
Loading