mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
55946: Remove href-to-uuid index cache on mapping
This commit is contained in:
@@ -8,7 +8,7 @@ import { Collection } from '../../core/shared/collection.model';
|
|||||||
import { SearchConfigurationService } from '../../+search-page/search-service/search-configuration.service';
|
import { SearchConfigurationService } from '../../+search-page/search-service/search-configuration.service';
|
||||||
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
|
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
|
||||||
import { PaginatedList } from '../../core/data/paginated-list';
|
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 { getSucceededRemoteData, toDSpaceObjectListRD } from '../../core/shared/operators';
|
||||||
import { SearchService } from '../../+search-page/search-service/search.service';
|
import { SearchService } from '../../+search-page/search-service/search.service';
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -12,17 +12,17 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
import { PaginatedList } from './paginated-list';
|
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 { hasValue, isNotEmptyOperator } from '../../shared/empty.util';
|
||||||
import { GetRequest } from './request.models';
|
import { GetRequest } from './request.models';
|
||||||
import {
|
import { configureRequest } from '../shared/operators';
|
||||||
configureRequest
|
|
||||||
} from '../shared/operators';
|
|
||||||
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
|
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
|
||||||
import { GenericConstructor } from '../shared/generic-constructor';
|
import { GenericConstructor } from '../shared/generic-constructor';
|
||||||
import { ResponseParsingService } from './parsing.service';
|
import { ResponseParsingService } from './parsing.service';
|
||||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
import { DSOResponseParsingService } from './dso-response-parsing.service';
|
import { DSOResponseParsingService } from './dso-response-parsing.service';
|
||||||
|
import { IndexName, IndexState } from '../index/index.reducer';
|
||||||
|
import { RemoveFromIndexBySubstringAction } from '../index/index.actions';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
|
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
|
||||||
@@ -34,7 +34,8 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
|
|||||||
protected store: Store<CoreState>,
|
protected store: Store<CoreState>,
|
||||||
protected cds: CommunityDataService,
|
protected cds: CommunityDataService,
|
||||||
protected halService: HALEndpointService,
|
protected halService: HALEndpointService,
|
||||||
protected objectCache: ObjectCacheService
|
protected objectCache: ObjectCacheService,
|
||||||
|
protected indexStore: Store<IndexState>
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -68,4 +69,10 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
|
|||||||
return this.rdbService.buildList(href$);
|
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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,8 @@ import { IndexName } from './index.reducer';
|
|||||||
*/
|
*/
|
||||||
export const IndexActionTypes = {
|
export const IndexActionTypes = {
|
||||||
ADD: type('dspace/core/index/ADD'),
|
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 */
|
/* tslint:disable:max-classes-per-file */
|
||||||
@@ -60,6 +61,30 @@ export class RemoveFromIndexByValueAction implements Action {
|
|||||||
this.payload = { name, value };
|
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 */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
|
||||||
|
@@ -2,7 +2,8 @@ import {
|
|||||||
IndexAction,
|
IndexAction,
|
||||||
IndexActionTypes,
|
IndexActionTypes,
|
||||||
AddToIndexAction,
|
AddToIndexAction,
|
||||||
RemoveFromIndexByValueAction
|
RemoveFromIndexByValueAction,
|
||||||
|
RemoveFromIndexBySubstringAction
|
||||||
} from './index.actions';
|
} from './index.actions';
|
||||||
|
|
||||||
export enum IndexName {
|
export enum IndexName {
|
||||||
@@ -31,6 +32,10 @@ export function indexReducer(state = initialState, action: IndexAction): IndexSt
|
|||||||
return removeFromIndexByValue(state, action as RemoveFromIndexByValueAction)
|
return removeFromIndexByValue(state, action as RemoveFromIndexByValueAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case IndexActionTypes.REMOVE_BY_SUBSTRING: {
|
||||||
|
return removeFromIndexBySubstring(state, action as RemoveFromIndexBySubstringAction)
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -60,3 +65,16 @@ function removeFromIndexByValue(state: IndexState, action: RemoveFromIndexByValu
|
|||||||
[action.payload.name]: newSubState
|
[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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user