From 79207847cb4277080016df827ea0e99df8041e98 Mon Sep 17 00:00:00 2001 From: "Andreas J. Koenig" Date: Sun, 27 Jun 2010 10:53:49 +0200 Subject: [PATCH] pull truncate out of the loop and move it after it; all tests pass --- lib/File/Rsync/Mirror/Recentfile.pm | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/File/Rsync/Mirror/Recentfile.pm b/lib/File/Rsync/Mirror/Recentfile.pm index 04a3783..e8e488e 100644 --- a/lib/File/Rsync/Mirror/Recentfile.pm +++ b/lib/File/Rsync/Mirror/Recentfile.pm @@ -1996,6 +1996,8 @@ sub _locked_batch_update { unless ($canonmeth) { $canonmeth = "naive_path_normalize"; } + my $oldest_allowed = 0; + my $setting_new_dirty_mark = 0; ITEM: for my $item (@$batch) { my($path,$type,$dirty_epoch) = @{$item}{qw(path type epoch)}; if (defined $path or defined $type or defined $dirty_epoch) { @@ -2010,14 +2012,7 @@ sub _locked_batch_update { } else { $epoch = $self->_epoch_monotonically_increasing($now,$recent); } - - # XXX truncate should go out of batch loop: old code had the - # order first truncate, then inject new value but when we have - # more than one item to inject we may have more than one - # dirty_epoch and dirty_mark may change or not. So maybe we - # can truncate better after the loop than before it? $recent ||= []; - my $oldest_allowed = 0; my $merged = $self->merged; if ($merged->{epoch}) { my $virtualnow = _bigfloatmax($now,$epoch); @@ -2026,15 +2021,6 @@ sub _locked_batch_update { } else { # as long as we are not merged at all, no limits! } - TRUNCATE: while (@$recent) { - # $DB::single++ unless defined $oldest_allowed; - if (_bigfloatlt($recent->[-1]{epoch}, $oldest_allowed)) { - pop @$recent; - $something_done = 1; - } else { - last TRUNCATE; - } - } if (defined $path && $path =~ s|^\Q$lrd\E||) { $path =~ s|^/||; my $splicepos; @@ -2050,6 +2036,7 @@ sub _locked_batch_update { $new_dm = $epoch; } $self->dirtymark($new_dm); + $setting_new_dirty_mark = 1; my $merged = $self->merged; if (not defined $merged->{epoch} or _bigfloatlt($epoch,$merged->{epoch})) { $self->merged(+{}); @@ -2064,6 +2051,18 @@ sub _locked_batch_update { $something_done = 1; } } + if ($setting_new_dirty_mark) { + $oldest_allowed = 0; + } +TRUNCATE: while (@$recent) { + # $DB::single++ unless defined $oldest_allowed; + if (_bigfloatlt($recent->[-1]{epoch}, $oldest_allowed)) { + pop @$recent; + $something_done = 1; + } else { + last TRUNCATE; + } + } return {something_done=>$something_done,recent=>$recent}; } -- 2.11.4.GIT