New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gui, lib/model: Disable periodic cleanup when versions are kept forever (fixes #8350) #8994
base: main
Are you sure you want to change the base?
gui, lib/model: Disable periodic cleanup when versions are kept forever (fixes #8350) #8994
Conversation
…er (fixes syncthing#8350) Currently, the cleanup is set to run on a periodic timer regardless of the days to keep versions. Because of this, even if versions are set to be kept forever, the cleanup still runs on the timer. Furthermore, the cleanup also runs even when using external versioning in spite of it doing nothing for that versioning type. This changes the behaviour as follows. 1. Cleanup is disabled when using external versioning. 2. Cleanup only runs when the days to keep versions are set to a value higher than "0". 3. When using Trash Can, Simple or Staggered versioning with the value above set to "0", the cleanup being "Disabled" is displayed in the folder information in the GUI even if the cleanup value is at its default. 4. In addition to the above, the cleanup input field is automatically disabled with a warning message informing the user about it being disabled when the number of days is set to "0". Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
@@ -161,7 +171,7 @@ func (f *folder) Serve(ctx context.Context) error { | |||
|
|||
// If we're configured to not do version cleanup, or we don't have a | |||
// versioner, cancel and drain that timer now. | |||
if f.versionCleanupInterval == 0 || f.versioner == nil { | |||
if f.versionCleanupInterval == 0 || ((f.versionType == "trashcan" || f.versionType == "simple") && f.versionCleanoutDays == 0) || (f.versionType == "staggered" && f.versionMaxAge == 0) || f.versionType == "external" || f.versioner == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuff could in fact happen in the constructor instead, then we don't need to have instance variables for all this stuff and it would keep things more contained, I think... We could also break up and comment the very long if clause a little bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea overall! I really like it, having recently stumbled over strange versioning settings being displayed in the GUI.
Some streamlining to keep this code easier to read and maintain would be in order, see comments 😉
<span ng-if="folder.versioning.cleanupIntervalS != versioningDefaults.cleanupIntervalS" tooltip data-original-title="{{'Cleanup Interval' | translate}}"> | ||
 <span class="fa fa-recycle"></span> <span ng-if="folder.versioning.cleanupIntervalS == 0" translate>Disabled</span><span ng-if="folder.versioning.cleanupIntervalS > 0">{{folder.versioning.cleanupIntervalS | duration}}</span> | ||
<span ng-if="folder.versioning.cleanupIntervalS != versioningDefaults.cleanupIntervalS || (folder.versioning.cleanupIntervalS == versioningDefaults.cleanupIntervalS && (((folder.versioning.type == 'trashcan' || folder.versioning.type == 'simple') && folder.versioning.params.cleanoutDays == 0) || (folder.versioning.type == 'staggered' && folder.versioning.params.maxAge == 0)))" tooltip data-original-title="{{'Cleanup Interval' | translate}}"> | ||
 <span class="fa fa-recycle"></span> <span ng-if="folder.versioning.cleanupIntervalS == 0 || (((folder.versioning.type == 'trashcan' || folder.versioning.type == 'simple') && folder.versioning.params.cleanoutDays == 0) || (folder.versioning.type == 'staggered' && folder.versioning.params.maxAge == 0))" translate>Disabled</span><span ng-if="folder.versioning.cleanupIntervalS > 0 && (((folder.versioning.type == 'trashcan' || folder.versioning.type == 'simple') && folder.versioning.params.cleanoutDays != 0) || (folder.versioning.type == 'staggered' && folder.versioning.params.maxAge != 0))">{{folder.versioning.cleanupIntervalS | duration}}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is way too much controller logic coded into the GUI presentation for my taste. Please if there is no easier way to determine all these conditions, then at least move it to the controller JS code, encapsulated as a function. Stuff like this tends to get forgotten when the underlying logic changes (such as when a new versioning scheme gets introduced). So more visibility and ideally close to the versioning code itself is better for maintenance.
<div class="input-group-addon" translate>seconds</div> | ||
</div> | ||
<p class="help-block"> | ||
<span translate ng-if="folderEditor.cleanupIntervalS.$valid || folderEditor.cleanupIntervalS.$pristine"class="help-block">The interval, in seconds, for running cleanup in the versions directory. Zero to disable periodic cleaning.</span> | ||
<span translate ng-if="folderEditor.cleanupIntervalS.$error.required && folderEditor.cleanupIntervalS.$dirty">The cleanup interval cannot be blank.</span> | ||
<span translate ng-if="folderEditor.cleanupIntervalS.$error.min && folderEditor.cleanupIntervalS.$dirty">The interval must be a positive number of seconds.</span> | ||
<span class="text-warning" ng-if="(((currentFolder._guiVersioning.selector == 'trashcan' || currentFolder._guiVersioning.selector == 'simple') && currentFolder._guiVersioning.trashcanClean == 0) || (currentFolder._guiVersioning.selector == 'staggered' && currentFolder._guiVersioning.staggeredMaxAge == 0))"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this logic is repeated in several places. One more reason to factor it out into a controller method.
gui, lib/model: Disable periodic cleanup when versions are kept forever (fixes #8350)
Currently, the cleanup is set to run on a periodic timer regardless of
the days to keep versions. Because of this, even if versions are set to
be kept forever, the cleanup still runs on the timer. Furthermore, the
cleanup also runs even when using external versioning in spite of it
doing nothing for that versioning type.
This changes the behaviour as follows.
higher than "0".
above set to "0", the cleanup being "Disabled" is displayed in the
folder information in the GUI even if the cleanup value is at its
default.
disabled with a warning message informing the user about it being
disabled when the number of days is set to "0".
Screenshots