Skip to content
Snippets Groups Projects
Commit f368da7a authored by Art Lowel's avatar Art Lowel
Browse files

fix issue where requestservice.getByUUID wouldn't work for requests that were...

fix issue where requestservice.getByUUID wouldn't work for requests that were never sent because there was already a copy in the cache
parent 6850a47d
Branches
No related merge requests found
......@@ -3,9 +3,9 @@ import { HttpHeaders } from '@angular/common/http';
import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
import { Observable, race as observableRace } from 'rxjs';
import { filter, map, mergeMap, take } from 'rxjs/operators';
import { filter, map, mergeMap, take, switchMap } from 'rxjs/operators';
import { cloneDeep, remove } from 'lodash';
import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
import { hasValue, isEmpty, isNotEmpty, hasValueOperator } from '../../shared/empty.util';
import { CacheableObject } from '../cache/object-cache.reducer';
import { ObjectCacheService } from '../cache/object-cache.service';
import { CoreState } from '../core.reducers';
......@@ -111,13 +111,22 @@ export class RequestService {
*/
getByUUID(uuid: string): Observable<RequestEntry> {
return observableRace(
this.store.pipe(select(entryFromUUIDSelector(uuid))),
this.store.pipe(
select(entryFromUUIDSelector(uuid)),
hasValueOperator()
),
this.store.pipe(
select(originalRequestUUIDFromRequestUUIDSelector(uuid)),
mergeMap((originalUUID) => {
return this.store.pipe(select(entryFromUUIDSelector(originalUUID)))
switchMap((originalUUID) => {
if (hasValue(originalUUID)) {
return this.store.pipe(select(entryFromUUIDSelector(originalUUID)))
} else {
return []
}
},
))
),
hasValueOperator()
)
).pipe(
map((entry: RequestEntry) => {
// Headers break after being retrieved from the store (because of lazy initialization)
......@@ -137,7 +146,14 @@ export class RequestService {
getByHref(href: string): Observable<RequestEntry> {
return this.store.pipe(
select(uuidFromHrefSelector(href)),
mergeMap((uuid: string) => this.getByUUID(uuid))
mergeMap((uuid: string) => {
if (isNotEmpty(uuid)) {
return this.getByUUID(uuid);
}
else {
return [undefined];
}
})
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment