55946: Remove href-to-uuid index cache on mapping

This commit is contained in:
Kristof De Langhe
2018-11-23 17:58:14 +01:00
parent aa172b6c68
commit e275fe590b
4 changed files with 62 additions and 8 deletions

View File

@@ -8,7 +8,7 @@ import { Collection } from '../../core/shared/collection.model';
import { SearchConfigurationService } from '../../+search-page/search-service/search-configuration.service';
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
import { PaginatedList } from '../../core/data/paginated-list';
import { map, switchMap } from 'rxjs/operators';
import { map, switchMap, take } from 'rxjs/operators';
import { getSucceededRemoteData, toDSpaceObjectListRD } from '../../core/shared/operators';
import { SearchService } from '../../+search-page/search-service/search.service';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
@@ -152,6 +152,10 @@ export class CollectionItemMapperComponent implements OnInit {
});
}
});
this.collectionRD$.pipe(take(1)).subscribe((collectionRD: RemoteData<Collection>) => {
this.collectionDataService.clearMappingItemsRequests(collectionRD.payload.id);
});
}
/**

View File

@@ -12,17 +12,17 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { Observable } from 'rxjs';
import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list';
import { distinctUntilChanged, map } from 'rxjs/operators';
import { distinctUntilChanged, map, take } from 'rxjs/operators';
import { hasValue, isNotEmptyOperator } from '../../shared/empty.util';
import { GetRequest } from './request.models';
import {
configureRequest
} from '../shared/operators';
import { configureRequest } from '../shared/operators';
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
import { GenericConstructor } from '../shared/generic-constructor';
import { ResponseParsingService } from './parsing.service';
import { DSpaceObject } from '../shared/dspace-object.model';
import { DSOResponseParsingService } from './dso-response-parsing.service';
import { IndexName, IndexState } from '../index/index.reducer';
import { RemoveFromIndexBySubstringAction } from '../index/index.actions';
@Injectable()
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
@@ -34,7 +34,8 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
protected store: Store<CoreState>,
protected cds: CommunityDataService,
protected halService: HALEndpointService,
protected objectCache: ObjectCacheService
protected objectCache: ObjectCacheService,
protected indexStore: Store<IndexState>
) {
super();
}
@@ -68,4 +69,10 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
return this.rdbService.buildList(href$);
}
clearMappingItemsRequests(collectionId: string) {
this.getMappingItemsEndpoint(collectionId).pipe(take(1)).subscribe((href: string) => {
this.indexStore.dispatch(new RemoveFromIndexBySubstringAction(IndexName.REQUEST, href));
});
}
}

View File

@@ -8,7 +8,8 @@ import { IndexName } from './index.reducer';
*/
export const IndexActionTypes = {
ADD: type('dspace/core/index/ADD'),
REMOVE_BY_VALUE: type('dspace/core/index/REMOVE_BY_VALUE')
REMOVE_BY_VALUE: type('dspace/core/index/REMOVE_BY_VALUE'),
REMOVE_BY_SUBSTRING: type('dspace/core/index/REMOVE_BY_SUBSTRING')
};
/* tslint:disable:max-classes-per-file */
@@ -60,6 +61,30 @@ export class RemoveFromIndexByValueAction implements Action {
this.payload = { name, value };
}
}
/**
* An ngrx action to remove multiple values from the index by substring
*/
export class RemoveFromIndexBySubstringAction implements Action {
type = IndexActionTypes.REMOVE_BY_SUBSTRING;
payload: {
name: IndexName,
value: string
};
/**
* Create a new RemoveFromIndexByValueAction
*
* @param name
* the name of the index to remove from
* @param value
* the value to remove the UUID for
*/
constructor(name: IndexName, value: string) {
this.payload = { name, value };
}
}
/* tslint:enable:max-classes-per-file */

View File

@@ -2,7 +2,8 @@ import {
IndexAction,
IndexActionTypes,
AddToIndexAction,
RemoveFromIndexByValueAction
RemoveFromIndexByValueAction,
RemoveFromIndexBySubstringAction
} from './index.actions';
export enum IndexName {
@@ -31,6 +32,10 @@ export function indexReducer(state = initialState, action: IndexAction): IndexSt
return removeFromIndexByValue(state, action as RemoveFromIndexByValueAction)
}
case IndexActionTypes.REMOVE_BY_SUBSTRING: {
return removeFromIndexBySubstring(state, action as RemoveFromIndexBySubstringAction)
}
default: {
return state;
}
@@ -60,3 +65,16 @@ function removeFromIndexByValue(state: IndexState, action: RemoveFromIndexByValu
[action.payload.name]: newSubState
});
}
function removeFromIndexBySubstring(state: IndexState, action: RemoveFromIndexByValueAction): IndexState {
const subState = state[action.payload.name];
const newSubState = Object.create(null);
for (const value in subState) {
if (value.indexOf(action.payload.value) < 0) {
newSubState[value] = subState[value];
}
}
return Object.assign({}, state, {
[action.payload.name]: newSubState
});
}