Remove recursive topic removal limit

This commit is contained in:
Thomas Nordquist
2019-07-23 00:36:15 +02:00
parent 6781170b85
commit 39d87d5a8e
4 changed files with 25 additions and 37 deletions

View File

@@ -5,14 +5,12 @@ import { makePublishEvent, rendererEvents } from '../../../events'
import { moveSelectionUpOrDownwards } from './visibleTreeTraversal'
import { globalActions } from '.'
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicClearLimit = 50) => async (
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
if (recursive) {
const topicCount = topic.childTopicCount()
const deleteLimitMessage =
topicCount > subtopicClearLimit ? ` You can only delete ${subtopicClearLimit} child topics at once.` : ''
const topicDelta = topic.hasMessage() ? -1 : 0
const childTopicsMessage =
@@ -23,7 +21,7 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicC
const confirmed = await dispatch(
globalActions.requestConfirmation(
'Confirm delete',
`Do you want to delete "${topic.path()}"${childTopicsMessage}?${deleteLimitMessage}`
`Do you want to delete "${topic.path()}"${childTopicsMessage}?`
)
)
if (!confirmed) {
@@ -38,27 +36,19 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicC
return
}
const publishEvent = makePublishEvent(connectionId)
const mqttMessage = {
topic: topic.path(),
payload: null,
retain: true,
qos: 0 as 0,
}
rendererEvents.emit(publishEvent, mqttMessage)
if (recursive) {
topic
.childTopics()
.filter(topic => Boolean(topic.message && topic.message.value))
.slice(0, subtopicClearLimit)
.forEach((topic, idx) => {
const mqttMessage = {
topic: topic.path(),
payload: null,
retain: true,
qos: 0 as 0,
}
// Rate limit deletion
setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx)
})
}
const topicsForPurging = recursive ? [topic, ...topic.childTopics()] : [topic]
topicsForPurging
.filter(t => t.path() !== '' && t.hasMessage())
.map(t => t.path())
.forEach((path, idx) => {
const mqttMessage = {
topic: path,
payload: null,
retain: true,
qos: 0 as 0,
}
// Rate limit deletion
setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx)
})
}