Skip to content

Commit 218c8be

Browse files
authored
Merge pull request #914 from oskarhane/fix-queing
Block background queries until the prev is finished
2 parents 6145c99 + c00d967 commit 218c8be

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/shared/modules/dbMeta/dbMetaDuck.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const UPDATE_SERVER = 'meta/UPDATE_SERVER'
4545
export const UPDATE_SETTINGS = 'meta/UPDATE_SETTINGS'
4646
export const CLEAR = 'meta/CLEAR'
4747
export const FORCE_FETCH = 'meta/FORCE_FETCH'
48+
export const DB_META_DONE = 'meta/DB_META_DONE'
4849

4950
/**
5051
* Selectors
@@ -292,6 +293,8 @@ export const dbMetaEpic = (some$, store) =>
292293
return (
293294
Rx.Observable.timer(1, 20000)
294295
.merge(some$.ofType(FORCE_FETCH))
296+
// Throw away newly initiated calls until done
297+
.throttle(() => some$.ofType(DB_META_DONE))
295298
// Labels, types and propertyKeys
296299
.mergeMap(() =>
297300
Rx.Observable.fromPromise(
@@ -342,7 +345,7 @@ export const dbMetaEpic = (some$, store) =>
342345
.filter(connectionLossFilter)
343346
.merge(some$.ofType(DISCONNECTION_SUCCESS))
344347
)
345-
.mapTo({ type: 'NOOP' })
348+
.mapTo({ type: DB_META_DONE })
346349
)
347350
})
348351

src/shared/modules/jmx/jmxDuck.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { getBackgroundTxMetadata } from 'shared/services/bolt/txMetadata'
4141
export const NAME = 'jmx'
4242
export const UPDATE = NAME + '/UPDATE'
4343
export const UPDATE_JMX_VALUES = NAME + '/UPDATE_JMX_VALUES'
44+
export const UPDATE_JMX_VALUES_DONE = NAME + '/UPDATE_JMX_VALUES_DONE'
4445

4546
/**
4647
* Selectors
@@ -140,20 +141,24 @@ export const jmxEpic = (some$, store) =>
140141
.filter(s => s.state === CONNECTED_STATE)
141142
.merge(some$.ofType(CONNECTION_SUCCESS))
142143
.mergeMap(() => {
143-
return Rx.Observable.timer(0, 20000)
144-
.merge(some$.ofType(FORCE_FETCH))
145-
.mergeMap(() =>
146-
Rx.Observable.fromPromise(fetchJmxValues(store)).catch(() =>
147-
Rx.Observable.of([])
144+
return (
145+
Rx.Observable.timer(0, 20000)
146+
.merge(some$.ofType(FORCE_FETCH))
147+
// Throw away new calls until we're finished
148+
.throttle(() => some$.ofType(UPDATE_JMX_VALUES_DONE))
149+
.mergeMap(() =>
150+
Rx.Observable.fromPromise(fetchJmxValues(store)).catch(() =>
151+
Rx.Observable.of([])
152+
)
148153
)
149-
)
150-
.filter(r => r)
151-
.do(res => store.dispatch(updateJmxValues(res)))
152-
.takeUntil(
153-
some$
154-
.ofType(LOST_CONNECTION)
155-
.filter(connectionLossFilter)
156-
.merge(some$.ofType(DISCONNECTION_SUCCESS))
157-
)
158-
.mapTo({ type: 'NOOP' })
154+
.filter(r => r)
155+
.do(res => store.dispatch(updateJmxValues(res)))
156+
.takeUntil(
157+
some$
158+
.ofType(LOST_CONNECTION)
159+
.filter(connectionLossFilter)
160+
.merge(some$.ofType(DISCONNECTION_SUCCESS))
161+
)
162+
.mapTo({ type: UPDATE_JMX_VALUES_DONE })
163+
)
159164
})

0 commit comments

Comments
 (0)