Improve freshness test
authorMike Rylander <mrylander@gmail.com>
Thu, 28 May 2020 20:41:36 +0000 (16:41 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 28 May 2020 21:02:46 +0000 (17:02 -0400)
Instead of returning the most recent timestamp for various .latest
calls, we will return the md5_hex hash of the list of IDs for the
relevant appointments.  This will catch new earlier-time requests.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm

index 80e060a..a6369d1 100644 (file)
@@ -14,6 +14,8 @@ use OpenILS::Utils::Fieldmapper;
 use OpenILS::Application::AppUtils;
 my $U = "OpenILS::Application::AppUtils";
 
+use Digest::MD5 qw(md5_hex);
+
 use DateTime;
 use DateTime::Format::ISO8601;
 
@@ -117,11 +119,10 @@ sub fetch_latest_delivered { # returns appointments delivered TODAY
         arrival => { '!=' => undef},
         delivered => { '>' => 'today'},
     },{
-        limit => 1,
-        order_by => { acsp => {delivered => {direction => 'desc'}} }
+        idlist => 1, order_by => { acsp => {delivered => {direction => 'desc'}} }
     }]);
 
-    return @$slots ? $$slots[0]->delivered : undef;
+    return md5_hex( join(',', @$slots) );
 }
 __PACKAGE__->register_method(
     method   => "fetch_latest_delivered",
@@ -131,7 +132,7 @@ __PACKAGE__->register_method(
             {type => 'string', desc => 'Authentication token'},
             {type => 'number', desc => 'Library ID'},
         ],
-        return => { desc => 'Most recent delivery timestamp from today, or error event'}
+        return => { desc => 'Hash of appointment IDs delivered today, or error event'}
     }
 );
 
@@ -205,10 +206,10 @@ sub fetch_latest_arrived {
         arrival => { '!=' => undef},
         delivered => undef,
     },{
-        limit => 1, order_by => { acsp => { arrival => { direction => 'desc' } } }
+        idlist => 1, order_by => { acsp => { arrival => { direction => 'desc' } } }
     }]);
 
-    return @$slots ? $$slots[0]->arrival : undef;
+    return md5_hex( join(',', @$slots) );
 }
 __PACKAGE__->register_method(
     method   => "fetch_latest_arrived",
@@ -218,7 +219,7 @@ __PACKAGE__->register_method(
             {type => 'string', desc => 'Authentication token'},
             {type => 'number', desc => 'Library ID'},
         ],
-        return => { desc => 'Most recent arrival time on undelivered appointments'}
+        return => { desc => 'Hash of appointment IDs for undelivered appointments'}
     }
 );
 
@@ -292,10 +293,14 @@ sub fetch_latest_staged {
         staged => { '!=' => undef},
         arrival => undef
     },{
-        limit => 1, order_by => { acsp => { slot => { direction => 'desc' } } }
+        idlist => 1, # fully ordered IDs will capture insertion, deletion, AND edit
+        order_by => [
+            { class => acsp => field => slot => direction => 'desc' },
+            { class => acsp => field => id   => direction => 'desc' }
+        ]
     }]);
 
-    return @$slots ? $$slots[0]->staged : undef;
+    return md5_hex( join(',', @$slots) );
 }
 __PACKAGE__->register_method(
     method   => "fetch_latest_staged",
@@ -305,7 +310,7 @@ __PACKAGE__->register_method(
             {type => 'string', desc => 'Authentication token'},
             {type => 'number', desc => 'Library ID'},
         ],
-        return => { desc => 'Time of most recently staged appointment'}
+        return => { desc => 'Hash of appointment IDs for staged appointment'}
     }
 );
 
@@ -399,10 +404,14 @@ sub fetch_latest_to_be_staged {
         staged => undef,
         slot => { '<=' => $horizon->strftime('%FT%T%z') },
     },{
-        limit => 1, order_by => { acsp => { slot => { direction => 'desc' } } }
+        idlist => 1, # fully ordered IDs will capture insertion, deletion, AND edit
+        order_by => [
+            { class => acsp => field => slot => direction => 'desc' },
+            { class => acsp => field => id   => direction => 'desc' }
+        ]
     }]);
 
-    return @$slots ? $$slots[0]->slot : undef;
+    return md5_hex( join(',', @$slots) );
 }
 __PACKAGE__->register_method(
     method   => "fetch_latest_to_be_staged",
@@ -412,7 +421,7 @@ __PACKAGE__->register_method(
             {type => 'string', desc => 'Authentication token'},
             {type => 'number', desc => 'Library ID'},
         ],
-        return => { desc => 'Appointment time of the latest slot that needs to be staged'}
+        return => { desc => 'Hash of appointment IDs that needs to be staged'}
     }
 );