Indexer orders by ID for batch consistency
authorBill Erickson <berickxx@gmail.com>
Mon, 11 Feb 2019 17:11:10 +0000 (12:11 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 27 Oct 2021 15:43:35 +0000 (11:43 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm

index 86abb41..b9a7e1f 100644 (file)
@@ -218,22 +218,26 @@ sub get_bib_ids {
     my $stop_id = $state->{stop_record}; # TODO
     my $start_date = $state->{start_date};
 
-    my ($select, $from, $where, $order);
+    my ($select, $from, $where);
     if ($start_date) {
         $select = "SELECT id";
         $from   = "FROM elastic.bib_last_mod_date";
         $where  = "WHERE last_mod_date > '$start_date'";
-        $order  = "ORDER BY last_mod_date";
     } else {
         $select = "SELECT id";
         $from   = "FROM biblio.record_entry";
         $where  = "WHERE NOT deleted AND active";
-        $order  = "ORDER BY edit_date, id";
     }
 
     $where .= " AND id >= $start_id" if $start_id;
     $where .= " AND id <= $stop_id" if $stop_id;
 
+    # Ordering by ID is the simplest way to guarantee all requested
+    # records are processed, given that edit dates may not be unique
+    # and that we're using start_id/stop_id instead of OFFSET to
+    # define the batches.
+    my $order = "ORDER BY id";
+
     my $sql = "$select $from $where $order LIMIT $BIB_BATCH_SIZE";
 
     my $ids = $self->get_db_rows($sql);