Commit c5304170 authored by jocuri%softhome.net's avatar jocuri%softhome.net

Patch for bug 252889: Change Search.pm activity log joins to LEFT JOINS; patch…

Patch for bug 252889: Change Search.pm activity log joins to LEFT JOINS; patch by Joel Peshkin <bugreport@peshkin.net>, r=justdave, a=justdave.
parent 025df7c7
...@@ -70,6 +70,7 @@ sub init { ...@@ -70,6 +70,7 @@ sub init {
@fields = @$fieldsref if $fieldsref; @fields = @$fieldsref if $fieldsref;
my @specialchart; my @specialchart;
my @andlist; my @andlist;
my %chartfields;
&::GetVersionTable(); &::GetVersionTable();
...@@ -362,12 +363,12 @@ sub init { ...@@ -362,12 +363,12 @@ sub init {
"^(?:assigned_to|reporter|qa_contact),(?:notequals),(%\\w+%)" => sub { "^(?:assigned_to|reporter|qa_contact),(?:notequals),(%\\w+%)" => sub {
$term = "bugs.$f <> " . pronoun($1, $user); $term = "bugs.$f <> " . pronoun($1, $user);
}, },
"^(assigned_to|reporter)," => sub { "^(assigned_to|reporter),(?!changed)" => sub {
push(@supptables, "profiles AS map_$f"); push(@supptables, "profiles AS map_$f");
push(@wherepart, "bugs.$f = map_$f.userid"); push(@wherepart, "bugs.$f = map_$f.userid");
$f = "map_$f.login_name"; $f = "map_$f.login_name";
}, },
"^qa_contact," => sub { "^qa_contact,(?!changed)" => sub {
push(@supptables, push(@supptables,
"LEFT JOIN profiles map_qa_contact ON bugs.qa_contact = map_qa_contact.userid"); "LEFT JOIN profiles map_qa_contact ON bugs.qa_contact = map_qa_contact.userid");
$f = "COALESCE(map_$f.login_name,'')"; $f = "COALESCE(map_$f.login_name,'')";
...@@ -445,7 +446,7 @@ sub init { ...@@ -445,7 +446,7 @@ sub init {
&$ref; &$ref;
} }
}, },
"^cc," => sub { "^cc,(?!changed)" => sub {
my $chartseq = $chartid; my $chartseq = $chartid;
if ($chartid eq "") { if ($chartid eq "") {
$chartseq = "CC$sequence"; $chartseq = "CC$sequence";
...@@ -776,7 +777,7 @@ sub init { ...@@ -776,7 +777,7 @@ sub init {
$term); $term);
}, },
"^keywords," => sub { "^keywords,(?!changed)" => sub {
&::GetVersionTable(); &::GetVersionTable();
my @list; my @list;
my $table = "keywords_$chartid"; my $table = "keywords_$chartid";
...@@ -812,7 +813,7 @@ sub init { ...@@ -812,7 +813,7 @@ sub init {
} }
}, },
"^dependson," => sub { "^dependson,(?!changed)" => sub {
my $table = "dependson_" . $chartid; my $table = "dependson_" . $chartid;
push(@supptables, "dependencies $table"); push(@supptables, "dependencies $table");
$ff = "$table.$f"; $ff = "$table.$f";
...@@ -821,7 +822,7 @@ sub init { ...@@ -821,7 +822,7 @@ sub init {
push(@wherepart, "$table.blocked = bugs.bug_id"); push(@wherepart, "$table.blocked = bugs.bug_id");
}, },
"^blocked," => sub { "^blocked,(?!changed)" => sub {
my $table = "blocked_" . $chartid; my $table = "blocked_" . $chartid;
push(@supptables, "dependencies $table"); push(@supptables, "dependencies $table");
$ff = "$table.$f"; $ff = "$table.$f";
...@@ -830,7 +831,7 @@ sub init { ...@@ -830,7 +831,7 @@ sub init {
push(@wherepart, "$table.dependson = bugs.bug_id"); push(@wherepart, "$table.dependson = bugs.bug_id");
}, },
"^alias," => sub { "^alias,(?!changed)" => sub {
$ff = "COALESCE(bugs.alias, '')"; $ff = "COALESCE(bugs.alias, '')";
my $ref = $funcsbykey{",$t"}; my $ref = $funcsbykey{",$t"};
&$ref; &$ref;
...@@ -950,51 +951,45 @@ sub init { ...@@ -950,51 +951,45 @@ sub init {
$term = "NOT (" . join(" OR ", @list) . ")"; $term = "NOT (" . join(" OR ", @list) . ")";
} }
}, },
",changedbefore" => sub { ",(changedbefore|changedafter)" => sub {
my $table = "act_$chartid"; my $operator = ($t =~ /before/) ? '<' : '>';
my $ftable = "fielddefs_$chartid";
push(@supptables, "bugs_activity $table");
push(@supptables, "fielddefs $ftable");
push(@wherepart, "$table.bug_id = bugs.bug_id");
push(@wherepart, "$table.fieldid = $ftable.fieldid");
$term = "($ftable.name = '$f' AND $table.bug_when < $q)";
},
",changedafter" => sub {
my $table = "act_$chartid";
my $ftable = "fielddefs_$chartid";
push(@supptables, "bugs_activity $table");
push(@supptables, "fielddefs $ftable");
push(@wherepart, "$table.bug_id = bugs.bug_id");
push(@wherepart, "$table.fieldid = $ftable.fieldid");
$term = "($ftable.name = '$f' AND $table.bug_when > $q)";
},
",changedfrom" => sub {
my $table = "act_$chartid"; my $table = "act_$chartid";
my $ftable = "fielddefs_$chartid"; my $fieldid = $chartfields{$f};
push(@supptables, "bugs_activity $table"); if (!$fieldid) {
push(@supptables, "fielddefs $ftable"); ThrowCodeError("invalid_field_name", {field => $f});
push(@wherepart, "$table.bug_id = bugs.bug_id"); }
push(@wherepart, "$table.fieldid = $ftable.fieldid"); push(@supptables, "LEFT JOIN bugs_activity $table " .
$term = "($ftable.name = '$f' AND $table.removed = $q)"; "ON $table.bug_id = bugs.bug_id " .
"AND $table.fieldid = $fieldid " .
"AND $table.bug_when $operator " .
&::SqlQuote(SqlifyDate($v)) );
$term = "($table.bug_when IS NOT NULL)";
}, },
",changedto" => sub { ",(changedfrom|changedto)" => sub {
my $operator = ($t =~ /from/) ? 'removed' : 'added';
my $table = "act_$chartid"; my $table = "act_$chartid";
my $ftable = "fielddefs_$chartid"; my $fieldid = $chartfields{$f};
push(@supptables, "bugs_activity $table"); if (!$fieldid) {
push(@supptables, "fielddefs $ftable"); ThrowCodeError("invalid_field_name", {field => $f});
push(@wherepart, "$table.bug_id = bugs.bug_id"); }
push(@wherepart, "$table.fieldid = $ftable.fieldid"); push(@supptables, "LEFT JOIN bugs_activity $table " .
$term = "($ftable.name = '$f' AND $table.added = $q)"; "ON $table.bug_id = bugs.bug_id " .
"AND $table.fieldid = $fieldid " .
"AND $table.$operator = $q");
$term = "($table.bug_when IS NOT NULL)";
}, },
",changedby" => sub { ",changedby" => sub {
my $table = "act_$chartid"; my $table = "act_$chartid";
my $ftable = "fielddefs_$chartid"; my $fieldid = $chartfields{$f};
push(@supptables, "bugs_activity $table"); if (!$fieldid) {
push(@supptables, "fielddefs $ftable"); ThrowCodeError("invalid_field_name", {field => $f});
push(@wherepart, "$table.bug_id = bugs.bug_id"); }
push(@wherepart, "$table.fieldid = $ftable.fieldid");
my $id = &::DBNameToIdAndCheck($v); my $id = &::DBNameToIdAndCheck($v);
$term = "($ftable.name = '$f' AND $table.who = $id)"; push(@supptables, "LEFT JOIN bugs_activity $table " .
"ON $table.bug_id = bugs.bug_id " .
"AND $table.fieldid = $fieldid " .
"AND $table.who = $id");
$term = "($table.bug_when IS NOT NULL)";
}, },
); );
my @funcnames; my @funcnames;
...@@ -1120,11 +1115,10 @@ sub init { ...@@ -1120,11 +1115,10 @@ sub init {
# $suppstring = String which is pasted into query containing all table names # $suppstring = String which is pasted into query containing all table names
# get a list of field names to verify the user-submitted chart fields against # get a list of field names to verify the user-submitted chart fields against
my %chartfields; &::SendSQL("SELECT name, fieldid FROM fielddefs");
&::SendSQL("SELECT name FROM fielddefs");
while (&::MoreSQLData()) { while (&::MoreSQLData()) {
my ($name) = &::FetchSQLData(); my ($name, $id) = &::FetchSQLData();
$chartfields{$name} = 1; $chartfields{$name} = $id;
} }
$row = 0; $row = 0;
......
...@@ -503,6 +503,10 @@ ...@@ -503,6 +503,10 @@
The context [% context FILTER html %] is invalid (must be a number, The context [% context FILTER html %] is invalid (must be a number,
"file" or "patch"). "file" or "patch").
[% ELSIF error == "invalid_field_name" %]
[% title = "Invalid Field Name" %]
The field "[% name FILTER html %]" is invalid.
[% ELSIF error == "invalid_format" %] [% ELSIF error == "invalid_format" %]
[% title = "Invalid Format" %] [% title = "Invalid Format" %]
The format "[% format FILTER html %]" is invalid (must be one of The format "[% format FILTER html %]" is invalid (must be one of
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment