diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-11-18 11:41:28 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-11-18 11:41:28 -0800 |
commit | 6bead8d6f196872b9863aa902341697b43a5b067 (patch) | |
tree | b2d2e3751262a85b2b34f12de3683943a7dc58d3 /FS/FS/h_Common.pm | |
parent | 4df3cb3192930c482c07c8d8e077a736244d4fc6 (diff) |
optimize history search (invoice rending time for svc_ records with tons of changes), RT#32190
Diffstat (limited to 'FS/FS/h_Common.pm')
-rw-r--r-- | FS/FS/h_Common.pm | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/FS/FS/h_Common.pm b/FS/FS/h_Common.pm index 9b5ad09..87fb76d 100644 --- a/FS/FS/h_Common.pm +++ b/FS/FS/h_Common.pm @@ -52,19 +52,19 @@ sub sql_h_search { my( $notdeleted, $notdeleted_mr ) = ( '', '' ); if ( scalar(@_) && $_[0] ) { $notdeleted = - "AND 0 = ( SELECT COUNT(*) FROM $table as notdel - WHERE notdel.$pkey = maintable.$pkey - AND notdel.history_action = 'delete' - AND notdel.history_date > maintable.history_date - AND notdel.history_date <= $_[0] - )"; + "AND NOT EXISTS ( SELECT 1 FROM $table as notdel + WHERE notdel.$pkey = maintable.$pkey + AND notdel.history_action = 'delete' + AND notdel.history_date > maintable.history_date + AND notdel.history_date <= $_[0] + )"; $notdeleted_mr = - "AND 0 = ( SELECT COUNT(*) FROM $table as notdel_mr - WHERE notdel_mr.$pkey = mostrecent.$pkey - AND notdel_mr.history_action = 'delete' - AND notdel_mr.history_date > mostrecent.history_date - AND notdel_mr.history_date <= $_[0] - )"; + "AND NOT EXISTS ( SELECT 1 FROM $table as notdel_mr + WHERE notdel_mr.$pkey = mostrecent.$pkey + AND notdel_mr.history_action = 'delete' + AND notdel_mr.history_date > mostrecent.history_date + AND notdel_mr.history_date <= $_[0] + )"; } ( |