Skip to content
Snippets Groups Projects
Commit 79afa38a authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

54472: Fixed duplicate requests

parent 7f8fa9c1
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import { Router } from '@angular/router';
import { RemoteData } from '../../core/data/remote-data';
import { isNotEmpty } from '../../shared/empty.util';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { take } from 'rxjs/operators';
@Component({
selector: 'ds-create-community',
......@@ -21,7 +22,7 @@ export class CreateCommunityPageComponent {
public communityRDObs: Observable<RemoteData<Community>>;
public constructor(private communityDataService: CommunityDataService, private routeService: RouteService, private router: Router) {
this.parentUUID$ = this.routeService.getQueryParameterValue('parent');
this.parentUUID$ = this.routeService.getQueryParameterValue('parent').pipe(take(1));
this.parentUUID$.subscribe((uuid: string) => {
if (isNotEmpty(uuid)) {
this.communityRDObs = this.communityDataService.findById(uuid);
......@@ -44,7 +45,7 @@ export class CreateCommunityPageComponent {
uuid: uuid
})))
});
this.communityDataService.create(community).subscribe((rd: RemoteData<DSpaceObject>) => {
this.communityDataService.create(community).pipe(take(1)).subscribe((rd: RemoteData<DSpaceObject>) => {
console.log(rd);
if (rd.hasSucceeded) {
this.router.navigateByUrl('');
......
......@@ -19,7 +19,7 @@ import {
} from './request.models';
import { RequestService } from './request.service';
import { NormalizedObject } from '../cache/models/normalized-object.model';
import { distinctUntilChanged, map, share, switchMap, withLatestFrom } from 'rxjs/operators';
import { distinctUntilChanged, map, share, switchMap, take, withLatestFrom } from 'rxjs/operators';
import {
configureRequest,
filterSuccessfulResponses, getRequestFromSelflink, getRequestFromUUID,
......@@ -30,9 +30,8 @@ import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
import { HttpHeaders } from '@angular/common/http';
import { DSOSuccessResponse, GenericSuccessResponse } from '../cache/response-cache.models';
import { AuthService } from '../auth/auth.service';
import { DSpaceObject } from '../shared/dspace-object.model';
import { first } from 'rxjs/operator/first';
import { take } from 'rxjs/operator/take';
import { Collection } from '../shared/collection.model';
import { Community } from '../shared/community.model';
export abstract class DataService<TNormalized extends NormalizedObject, TDomain> {
protected abstract responseCache: ResponseCacheService;
......@@ -118,33 +117,38 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
}
public create(dso: TDomain): Observable<RemoteData<TDomain>> {
const request$ = this.halService.getEndpoint(this.linkPath).pipe(
const requestId = this.requestService.generateRequestId();
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
isNotEmptyOperator(),
distinctUntilChanged(),
withLatestFrom(this.buildCreateParams(dso)),
map(([endpointURL, params]) => {
map(([endpointURL, params]) => endpointURL + params)
);
const request$ = endpoint$.pipe(
take(1),
map((endpoint) => {
const options: HttpOptions = Object.create({});
const headers = new HttpHeaders();
headers.append('Authentication', this.authService.buildAuthHeader());
options.headers = headers;
return new CreateRequest(this.requestService.generateRequestId(), endpointURL + params, options);
return new CreateRequest(requestId, endpoint, options);
}),
configureRequest(this.requestService),
share()
configureRequest(this.requestService)
);
const href$ = request$.pipe(map((request: RestRequest) => request.href));
const uuid$ = request$.pipe(map((request: RestRequest) => request.uuid));
const requestEntry$ = uuid$.pipe(getRequestFromUUID(this.requestService));
const responseCache$ = href$.pipe(getResponseFromSelflink(this.responseCache));
const payload$ = responseCache$.pipe(
const payload$ = request$.pipe(
map((request: RestRequest) => request.href),
getResponseFromSelflink(this.responseCache),
filterSuccessfulResponses(),
map((entry: ResponseCacheEntry) => entry.response),
map((response: GenericSuccessResponse<TDomain>) => response.payload),
distinctUntilChanged()
);
const requestEntry$ = this.requestService.getByUUID(requestId);
const responseCache$ = endpoint$.pipe(getResponseFromSelflink(this.responseCache));
return this.rdbService.toRemoteDataObservable(requestEntry$, responseCache$, payload$);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment