From 574e369a5a52e9b388972e439a21efe53cf59972 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Wed, 19 Feb 2020 16:56:22 +0000
Subject: [PATCH] Bug 23571: (follow-up) Only look for overdues after obtaining
 the lock

No point in performing the overdues fetch before obtaining the lock and
knowing we can do something with them.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 misc/cronjobs/fines.pl | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl
index 2505e2f3a0..c543a17b47 100755
--- a/misc/cronjobs/fines.pl
+++ b/misc/cronjobs/fines.pl
@@ -123,11 +123,12 @@ if ($filename) {
     print {$fh} join $delim, ( @borrower_fields, @item_fields, @other_fields );
     print {$fh} "\n";
 }
-my $counted = 0;
-my $params;
-$params->{maximumdays} = $maxdays if $maxdays;
-my $overdues = Getoverdues($params);
+
 if(_flock($LockFH, LOCK_EX|LOCK_NB)) {
+    my $counted = 0;
+    my $params;
+    $params->{maximumdays} = $maxdays if $maxdays;
+    my $overdues = Getoverdues($params);
     for my $overdue ( @{$overdues} ) {
         next if $overdue->{itemlost};
 
-- 
2.20.1