aboutsummaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2015-04-05 21:35:18 +0200
committerFrédéric Buclin <LpSolit@gmail.com>2015-04-05 21:35:18 +0200
commitfcd445919eab36a4b1b1c415e9c20fabb2ec0ac0 (patch)
tree6bfb8ac6bf46592fd643ccb5799b3b755ba98a5a /Bugzilla
parent467bef6d90360a43bfdcaf2d24985cb171435bf9 (diff)
downloadbugs-fcd445919eab36a4b1b1c415e9c20fabb2ec0ac0.tar
bugs-fcd445919eab36a4b1b1c415e9c20fabb2ec0ac0.tar.gz
bugs-fcd445919eab36a4b1b1c415e9c20fabb2ec0ac0.tar.bz2
bugs-fcd445919eab36a4b1b1c415e9c20fabb2ec0ac0.tar.xz
bugs-fcd445919eab36a4b1b1c415e9c20fabb2ec0ac0.zip
Bug 1143867: Optimize set_comment_is_private() and isopened()
r=dkl a=sgreen
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Bug.pm42
1 files changed, 25 insertions, 17 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index a49656e07..abbb3fe57 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -2498,29 +2498,34 @@ sub reset_assigned_to {
}
sub set_bug_ignored { $_[0]->set('bug_ignored', $_[1]); }
sub set_cclist_accessible { $_[0]->set('cclist_accessible', $_[1]); }
+
sub set_comment_is_private {
- my ($self, $comment_id, $isprivate) = @_;
+ my ($self, $comments, $isprivate) = @_;
+ $self->{comment_isprivate} ||= [];
+ my $is_insider = Bugzilla->user->is_insider;
+
+ $comments = { $comments => $isprivate } unless ref $comments;
- # We also allow people to pass in a hash of comment ids to update.
- if (ref $comment_id) {
- while (my ($id, $is) = each %$comment_id) {
- $self->set_comment_is_private($id, $is);
+ foreach my $comment (@{$self->comments}) {
+ # Skip unmodified comment privacy.
+ next unless exists $comments->{$comment->id};
+
+ my $isprivate = delete $comments->{$comment->id} ? 1 : 0;
+ if ($isprivate != $comment->is_private) {
+ ThrowUserError('user_not_insider') unless $is_insider;
+ $comment->set_is_private($isprivate);
+ push @{$self->{comment_isprivate}}, $comment;
}
- return;
}
- my ($comment) = grep($comment_id == $_->id, @{ $self->comments });
- ThrowUserError('comment_invalid_isprivate', { id => $comment_id })
- if !$comment;
+ # If there are still entries in $comments, then they are illegal.
+ ThrowUserError('comment_invalid_isprivate', { id => join(', ', keys %$comments) })
+ if scalar keys %$comments;
- $isprivate = $isprivate ? 1 : 0;
- if ($isprivate != $comment->is_private) {
- ThrowUserError('user_not_insider') if !Bugzilla->user->is_insider;
- $self->{comment_isprivate} ||= [];
- $comment->set_is_private($isprivate);
- push @{$self->{comment_isprivate}}, $comment;
- }
+ # If no comment privacy has been modified, remove this key.
+ delete $self->{comment_isprivate} unless scalar @{$self->{comment_isprivate}};
}
+
sub set_component {
my ($self, $name) = @_;
my $old_comp = $self->component_obj;
@@ -3579,7 +3584,10 @@ sub flags {
sub isopened {
my $self = shift;
- return is_open_state($self->{bug_status}) ? 1 : 0;
+ unless (exists $self->{isopened}) {
+ $self->{isopened} = is_open_state($self->{bug_status}) ? 1 : 0;
+ }
+ return $self->{isopened};
}
sub keywords {