indexer start-date support
authorBill Erickson <berickxx@gmail.com>
Tue, 6 Nov 2018 15:52:59 +0000 (10:52 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 28 Aug 2019 21:41:55 +0000 (17:41 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.elastic-search.sql

index e451259..86abb41 100644 (file)
@@ -216,17 +216,25 @@ sub get_bib_ids {
 
     my $start_id = $state->{start_record} || 0;
     my $stop_id = $state->{stop_record}; # TODO
-
-    # TODO: implement start_date filtering.
-    # Requires checking edit dates on bibs, call numbers, and copies!
     my $start_date = $state->{start_date};
 
-    my $sql = <<SQL;
-SELECT bre.id
-FROM biblio.record_entry bre
-WHERE NOT bre.deleted AND bre.active AND bre.id >= $start_id
-ORDER BY bre.edit_date, bre.id LIMIT $BIB_BATCH_SIZE
-SQL
+    my ($select, $from, $where, $order);
+    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;
+
+    my $sql = "$select $from $where $order LIMIT $BIB_BATCH_SIZE";
 
     my $ids = $self->get_db_rows($sql);
     return [ map {$_->{id}} @$ids ];
index 97adf22..743f5f1 100644 (file)
@@ -134,6 +134,29 @@ BEGIN
     $$;
 END $FUNK$ LANGUAGE PLPGSQL;
 
+/* give me bibs I should upate */
+
+CREATE OR REPLACE VIEW elastic.bib_last_mod_date AS
+    WITH mod_dates AS (
+        SELECT bre.id, 
+            bre.edit_date, 
+            MAX(acn.edit_date) AS max_call_number_edit_date, 
+            MAX(acp.edit_date) AS max_copy_edit_date
+        FROM biblio.record_entry bre
+            JOIN asset.call_number acn ON (acn.record = bre.id)
+            JOIN asset.copy acp ON (acp.call_number = acn.id)
+        WHERE 
+            bre.active
+            AND NOT bre.deleted
+            AND NOT acn.deleted
+            AND NOT acp.deleted
+        GROUP BY 1, 2
+    ) SELECT dates.id, 
+        GREATEST(dates.edit_date, 
+            GREATEST(dates.max_call_number_edit_date, dates.max_copy_edit_date)
+        ) AS last_mod_date
+    FROM mod_dates dates;
+
 
 /* SEED DATA ------------------------------------------------------------ */