Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tomasz1986
Copy link
Contributor

@tomasz1986 tomasz1986 commented Jul 21, 2023

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.

  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".

Screenshots

image
image
image
image

…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 {
Copy link
Member

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.

Copy link
Member

@acolomb acolomb left a 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}}">
&ensp;<span class="fa fa-recycle"></span>&nbsp;<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}}">
&ensp;<span class="fa fa-recycle"></span>&nbsp;<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>
Copy link
Member

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))">
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syncthing keeps performing version cleanup even when using External Versioning
3 participants