From 8356a92aa3d42a06c8731fa901234d998d8503bd Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 9 Jun 2021 13:41:32 +0100 Subject: [PATCH] add an option to disable throttling of the loading of shared files on startup --- core/src/main/groovy/com/muwire/core/MuWireSettings.groovy | 3 +++ .../com/muwire/core/files/PersisterFolderService.groovy | 4 ++-- .../controllers/com/muwire/gui/OptionsController.groovy | 4 ++++ gui/griffon-app/i18n/messages.properties | 1 + gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy | 2 ++ gui/griffon-app/views/com/muwire/gui/OptionsView.groovy | 5 +++++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index 1f1649d4..cb590d94 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -31,6 +31,7 @@ class MuWireSettings { boolean shareHiddenFiles volatile int hashingCores Set ignoredFileTypes + boolean throttleLoadingFiles boolean searchComments boolean searchCollections boolean browseFiles @@ -101,6 +102,7 @@ class MuWireSettings { shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true")) shareHiddenFiles = Boolean.parseBoolean(props.getProperty("shareHiddenFiles","false")) hashingCores = Integer.parseInt(props.getProperty("hashingCores", String.valueOf(numHashingCores()))) + throttleLoadingFiles = Boolean.parseBoolean(props.getProperty("throttleLoadingFiles", "true")) downloadSequentialRatio = Float.valueOf(props.getProperty("downloadSequentialRatio","0.8")) hostClearInterval = Integer.valueOf(props.getProperty("hostClearInterval","15")) hostHopelessInterval = Integer.valueOf(props.getProperty("hostHopelessInterval", "60")) @@ -194,6 +196,7 @@ class MuWireSettings { props.setProperty("shareDownloadedFiles", String.valueOf(shareDownloadedFiles)) props.setProperty("shareHiddenFiles", String.valueOf(shareHiddenFiles)) props.setProperty("hashingCores", String.valueOf(hashingCores)) + props.setProperty("throttleLoadingFiles", String.valueOf(throttleLoadingFiles)) props.setProperty("downloadSequentialRatio", String.valueOf(downloadSequentialRatio)) props.setProperty("hostClearInterval", String.valueOf(hostClearInterval)) props.setProperty("hostHopelessInterval", String.valueOf(hostHopelessInterval)) diff --git a/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy b/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy index 96df4f3c..74bf7c1e 100644 --- a/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy @@ -141,7 +141,7 @@ class PersisterFolderService extends BasePersisterService { stream = stream.filter({ it.getFileName().toString().endsWith(".json") }) - if (core.muOptions.plugin) + if (core.muOptions.plugin || !core.muOptions.throttleLoadingFiles) stream = stream.parallel() stream.forEach({ log.fine("processing path $it") @@ -158,7 +158,7 @@ class PersisterFolderService extends BasePersisterService { log.fine("loaded file $event.loadedFile.file") listener.publish event - if (!core.muOptions.plugin) { + if (!core.muOptions.plugin && core.muOptions.throttleLoadingFiles) { loaded++ if (loaded % 10 == 0) Thread.sleep(20) diff --git a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy index 02474048..4b2f03bc 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy @@ -112,6 +112,10 @@ class OptionsController { model.ignoredFileTypes = text settings.ignoredFileTypes.clear() text.split(",").each {settings.ignoredFileTypes.add(it)} + + boolean throttleLoadingFiles = view.throttleLoadingFilesCheckbox.model.isSelected() + model.throttleLoadingFiles = throttleLoadingFiles + settings.throttleLoadingFiles = throttleLoadingFiles boolean browseFiles = view.browseFilesCheckbox.model.isSelected() model.browseFiles = browseFiles diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 0cb81a84..81d1110d 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -298,6 +298,7 @@ OPTIONS_SHARE_DOWNLOADED_FILES=Share downloaded files OPTIONS_SHARE_HIDDEN_FILES=Share hidden files OPTIONS_HASHING_CORES=CPU Cores to use when hashing OPTIONS_IGNORED_FILE_TYPES=File types to not share +OPTIONS_THROTTLE_LOADING_FILES=Throttle loading of shared files on startup OPTIONS_UPDATE_SETTINGS=Update Settings OPTIONS_CHECK_FOR_UPDATES=Check for updates every (hours) OPTIONS_DOWNLOAD_UPDATES=Download updates automatically diff --git a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy index 55c8aae0..7465c115 100644 --- a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy @@ -18,6 +18,7 @@ class OptionsModel { @Observable boolean shareDownloadedFiles @Observable boolean shareHiddenFiles @Observable int hashingCores + @Observable boolean throttleLoadingFiles @Observable String ignoredFileTypes @Observable String downloadLocation @Observable String incompleteLocation @@ -98,6 +99,7 @@ class OptionsModel { shareDownloadedFiles = settings.shareDownloadedFiles shareHiddenFiles = settings.shareHiddenFiles hashingCores = settings.hashingCores + throttleLoadingFiles = settings.throttleLoadingFiles ignoredFileTypes = settings.ignoredFileTypes.join(",") downloadLocation = settings.downloadLocation.getAbsolutePath() incompleteLocation = settings.incompleteLocation.getAbsolutePath() diff --git a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy index bb6411ad..c1ea295b 100644 --- a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy @@ -50,6 +50,7 @@ class OptionsView { def shareDownloadedCheckbox def shareHiddenCheckbox def hashingCoresTextField + def throttleLoadingFilesCheckbox def ignoredFileTypesTextField def searchCommentsCheckbox def searchCollectionsCheckbox @@ -182,6 +183,10 @@ class OptionsView { label(text : trans("OPTIONS_IGNORED_FILE_TYPES"), constraints : gbc(gridx: 0, gridy: 3, anchor: GridBagConstraints.LINE_START, weightx : 100)) ignoredFileTypesTextField = textField(text : bind {model.ignoredFileTypes}, columns: 25, constraints: gbc(gridx: 1, gridy: 3, anchor: GridBagConstraints.LINE_END, fill: GridBagConstraints.HORIZONTAL)) + + label(text : trans("OPTIONS_THROTTLE_LOADING_FILES"), constraints: gbc(gridx: 0, gridy: 4, anchor: GridBagConstraints.LINE_START, weightx: 100)) + throttleLoadingFilesCheckbox = checkBox(selected: bind{model.throttleLoadingFiles}, constraints: gbc(gridx: 1, gridy: 4, anchor: GridBagConstraints.LINE_END, + weightx: 0)) } if (!model.disableUpdates) {