mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 20:43:08 +00:00
fixed SSB commit delay
This commit is contained in:
@@ -11,7 +11,7 @@ import { ObjectCacheState } from '../cache/object-cache.reducer';
|
|||||||
describe('AuthResponseParsingService', () => {
|
describe('AuthResponseParsingService', () => {
|
||||||
let service: AuthResponseParsingService;
|
let service: AuthResponseParsingService;
|
||||||
|
|
||||||
const EnvConfig = { cache: { msToLive: 1000 } } as GlobalConfig;
|
const EnvConfig = { cache: { msToLive: 1000 } } as any;
|
||||||
const store = new MockStore<ObjectCacheState>({});
|
const store = new MockStore<ObjectCacheState>({});
|
||||||
const objectCacheService = new ObjectCacheService(store as any);
|
const objectCacheService = new ObjectCacheService(store as any);
|
||||||
|
|
||||||
|
26
src/app/core/cache/object-cache.reducer.spec.ts
vendored
26
src/app/core/cache/object-cache.reducer.spec.ts
vendored
@@ -8,6 +8,7 @@ import {
|
|||||||
RemoveFromObjectCacheAction,
|
RemoveFromObjectCacheAction,
|
||||||
ResetObjectCacheTimestampsAction
|
ResetObjectCacheTimestampsAction
|
||||||
} from './object-cache.actions';
|
} from './object-cache.actions';
|
||||||
|
import { Operation } from 'fast-json-patch';
|
||||||
|
|
||||||
class NullAction extends RemoveFromObjectCacheAction {
|
class NullAction extends RemoveFromObjectCacheAction {
|
||||||
type = null;
|
type = null;
|
||||||
@@ -21,6 +22,7 @@ class NullAction extends RemoveFromObjectCacheAction {
|
|||||||
describe('objectCacheReducer', () => {
|
describe('objectCacheReducer', () => {
|
||||||
const selfLink1 = 'https://localhost:8080/api/core/items/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
|
const selfLink1 = 'https://localhost:8080/api/core/items/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
|
||||||
const selfLink2 = 'https://localhost:8080/api/core/items/28b04544-1766-4e82-9728-c4e93544ecd3';
|
const selfLink2 = 'https://localhost:8080/api/core/items/28b04544-1766-4e82-9728-c4e93544ecd3';
|
||||||
|
const newName = 'new different name';
|
||||||
const testState = {
|
const testState = {
|
||||||
[selfLink1]: {
|
[selfLink1]: {
|
||||||
data: {
|
data: {
|
||||||
@@ -140,15 +142,31 @@ describe('objectCacheReducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should perform the ADD_PATCH action without affecting the previous state', () => {
|
it('should perform the ADD_PATCH action without affecting the previous state', () => {
|
||||||
const action = new AddPatchObjectCacheAction(selfLink1, [{ op: 'replace', path: '/name', value: 'random string' }]);
|
const action = new AddPatchObjectCacheAction(selfLink1, [{
|
||||||
|
op: 'replace',
|
||||||
|
path: '/name',
|
||||||
|
value: 'random string'
|
||||||
|
}]);
|
||||||
// testState has already been frozen above
|
// testState has already been frozen above
|
||||||
objectCacheReducer(testState, action);
|
objectCacheReducer(testState, action);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should perform the APPLY_PATCH action without affecting the previous state', () => {
|
it('should when the ADD_PATCH action dispatched', () => {
|
||||||
|
const patch = [{ op: 'add', path: '/name', value: newName } as Operation];
|
||||||
|
const action = new AddPatchObjectCacheAction(selfLink1, patch);
|
||||||
|
const newState = objectCacheReducer(testState, action);
|
||||||
|
expect(newState[selfLink1].patches.map((p) => p.operations)).toContain(patch);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should when the APPLY_PATCH action dispatched', () => {
|
||||||
|
const patch = [{ op: 'add', path: '/name', value: newName } as Operation];
|
||||||
|
const addPatchAction = new AddPatchObjectCacheAction(selfLink1, patch);
|
||||||
|
const stateWithPatch = objectCacheReducer(testState, addPatchAction);
|
||||||
|
|
||||||
const action = new ApplyPatchObjectCacheAction(selfLink1);
|
const action = new ApplyPatchObjectCacheAction(selfLink1);
|
||||||
// testState has already been frozen above
|
const newState = objectCacheReducer(stateWithPatch, action);
|
||||||
objectCacheReducer(testState, action);
|
expect(newState[selfLink1].patches).toEqual([]);
|
||||||
|
expect((newState[selfLink1].data as any).name).toEqual(newName);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { delay, exhaustMap, first, map, switchMap } from 'rxjs/operators';
|
import { delay, exhaustMap, first, map, switchMap, tap } from 'rxjs/operators';
|
||||||
import { Inject, Injectable } from '@angular/core';
|
import { Inject, Injectable } from '@angular/core';
|
||||||
import { Actions, Effect, ofType } from '@ngrx/effects';
|
import { Actions, Effect, ofType } from '@ngrx/effects';
|
||||||
import {
|
import {
|
||||||
@@ -38,7 +38,9 @@ export class ServerSyncBufferEffects {
|
|||||||
exhaustMap((action: AddToSSBAction) => {
|
exhaustMap((action: AddToSSBAction) => {
|
||||||
const autoSyncConfig = this.EnvConfig.cache.autoSync;
|
const autoSyncConfig = this.EnvConfig.cache.autoSync;
|
||||||
const timeoutInSeconds = autoSyncConfig.timePerMethod[action.payload.method] || autoSyncConfig.defaultTime;
|
const timeoutInSeconds = autoSyncConfig.timePerMethod[action.payload.method] || autoSyncConfig.defaultTime;
|
||||||
return observableOf(new CommitSSBAction(action.payload.method)).pipe(delay(timeoutInSeconds * 1000))
|
return observableOf(new CommitSSBAction(action.payload.method)).pipe(
|
||||||
|
delay(timeoutInSeconds * 1000),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ export class ServerSyncBufferEffects {
|
|||||||
switchMap((action: CommitSSBAction) => {
|
switchMap((action: CommitSSBAction) => {
|
||||||
return this.store.pipe(
|
return this.store.pipe(
|
||||||
select(serverSyncBufferSelector()),
|
select(serverSyncBufferSelector()),
|
||||||
|
first(), /* necessary, otherwise delay will not have any effect after the first run */
|
||||||
switchMap((bufferState: ServerSyncBufferState) => {
|
switchMap((bufferState: ServerSyncBufferState) => {
|
||||||
const actions: Array<Observable<Action>> = bufferState.buffer
|
const actions: Array<Observable<Action>> = bufferState.buffer
|
||||||
.filter((entry: ServerSyncBufferEntry) => {
|
.filter((entry: ServerSyncBufferEntry) => {
|
||||||
|
Reference in New Issue
Block a user