summaryrefslogtreecommitdiff
path: root/FS/FS/part_event_condition.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-05-03 14:01:26 -0700
committerIvan Kohler <ivan@freeside.biz>2014-05-03 14:01:26 -0700
commit05a570db47faf7d497663fa52914d1cb4750174a (patch)
tree41a47e63a058496b751b80811b4f92e680440db7 /FS/FS/part_event_condition.pm
parent53ac9ee9aff3755c4206f800a5d5a4dd8fc4242b (diff)
optimize event queries, RT#28978, possible MySQL band-aid, RT#28978
Notes
Notes: possible MySQL band-aid is actually RT#28895
Diffstat (limited to 'FS/FS/part_event_condition.pm')
-rw-r--r--FS/FS/part_event_condition.pm35
1 files changed, 23 insertions, 12 deletions
diff --git a/FS/FS/part_event_condition.pm b/FS/FS/part_event_condition.pm
index 78aa3b1a9..b51c6b901 100644
--- a/FS/FS/part_event_condition.pm
+++ b/FS/FS/part_event_condition.pm
@@ -253,7 +253,6 @@ B<where_conditions_sql>.
sub join_conditions_sql {
my ( $class, $eventtable ) = @_;
- my %conditions = $class->conditions( $eventtable );
join(' ',
map {
@@ -262,7 +261,8 @@ sub join_conditions_sql {
" AND cond_$_.conditionname = ". dbh->quote($_).
" )";
}
- keys %conditions
+ map $_->[0], $class->_where_conditions( $eventtable ) #, %options )
+
);
}
@@ -280,27 +280,38 @@ as passed to freeside-daily), as a UNIX timestamp.
sub where_conditions_sql {
my ( $class, $eventtable, %options ) = @_;
+ join(' AND ',
+ map { my $conditionname = $_->[0];
+ my $sql = $_->[1];
+ "( cond_$conditionname.conditionname IS NULL OR $sql )";
+ }
+ $class->_where_conditions( $eventtable, %options )
+ );
+}
+
+sub _where_conditions {
+ my ( $class, $eventtable, %options ) = @_;
+
my $time = $options{'time'};
my %conditions = $class->conditions( $eventtable );
- my $where = join(' AND ',
+ grep { $_->[1] !~ /^\s*true\s*$/i
+ || $conditions{ $_->[0] }->{order_sql}
+ }
map {
my $conditionname = $_;
my $coderef = $conditions{$conditionname}->{condition_sql};
+ #die "$coderef is not a CODEREF" unless ref($coderef) eq 'CODE';
my $sql = &$coderef( $eventtable, 'time' => $time,
'driver_name' => driver_name(),
);
- die "$coderef is not a CODEREF" unless ref($coderef) eq 'CODE';
- "( cond_$conditionname.conditionname IS NULL OR $sql )";
+ [ $_, $sql ];
}
- grep { my $cond = $_;
- ! grep { $_ eq $cond } @SKIP_CONDITION_SQL
- }
- keys %conditions
- );
-
- $where;
+ grep { my $cond = $_;
+ ! grep { $_ eq $cond } @SKIP_CONDITION_SQL
+ }
+ keys %conditions;
}
=item order_conditions_sql [ EVENTTABLE ]