LP#1846354: Move the deleted filter out of the query for speed collab/phasefx/consolidate_patron_notes_tweaked
authorMike Rylander <mrylander@gmail.com>
Thu, 10 Sep 2020 17:43:03 +0000 (13:43 -0400)
committerJason Etheridge <jason@EquinoxInitiative.org>
Fri, 11 Sep 2020 17:52:08 +0000 (13:52 -0400)
Also tweak the aump view so that PG can use better plans

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/sql/Pg/005.schema.actors.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.note_and_message_consolidation

index 3b9b362..7c6a6e1 100644 (file)
@@ -3305,18 +3305,21 @@ sub new_flesh_user {
     }
 
     if($fetch_notes) {
-        # grab undeleted notes (now actor.usr_message_penalty) that have not hit their stop_date
-        $user->notes(
-            $e->search_actor_usr_message_penalty([
+        # grab notes (now actor.usr_message_penalty) that have not hit their stop_date
+        # NOTE: This is a view that already filters out deleted messages that are not
+        # attached to a penalty, but the query is slow if we include deleted=f, so we
+        # post-filter that.  This counts both user messages and standing penalties, but
+        # linked ones are only counted once.
+        $user->notes([
+            grep { !$_->deleted or $_->deleted eq 'f' } @{ $e->search_actor_usr_message_penalty([
                 {   usr => $id,
-                    deleted => 'f',
                     '-or' => [
                         {stop_date => undef},
                         {stop_date => {'>' => 'now'}}
                     ],
                 }, {}
-            ])
-        );
+            ]) }
+        ]);
     }
 
     # retrieve the most recent usr_activity entry
index e699b35..b7e673c 100644 (file)
@@ -863,6 +863,7 @@ FULL OUTER JOIN
     actor.usr_message aum
 ON (
     ausp.usr_message = aum.id
+    AND ausp.usr = aum.usr
 )
 WHERE
     NOT (ausp.id IS NULL AND aum.deleted);
index 28c5c89..d86f1a4 100644 (file)
@@ -121,6 +121,7 @@ FULL OUTER JOIN
     actor.usr_message aum
 ON (
     ausp.usr_message = aum.id
+    AND ausp.usr = aum.usr
 )
 WHERE
     NOT (ausp.id IS NULL AND aum.deleted);