summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Bug.pm
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2012-11-28 09:40:21 +0100
committerByron Jones <bjones@mozilla.com>2012-11-28 09:40:21 +0100
commit1c5e0c47c92128afebef5614407d84cd72c12b35 (patch)
treefb192713a69dd8a61774f2fdb308a200d9a4e403 /Bugzilla/Bug.pm
parent4096dc51aadfa8344ae649c477827721a4c398ab (diff)
downloadbugzilla-1c5e0c47c92128afebef5614407d84cd72c12b35.tar.gz
bugzilla-1c5e0c47c92128afebef5614407d84cd72c12b35.tar.xz
Bug 814411: Add a caching mechanism to Bugzilla::Object to avoid querying the database repeatedly for the same information
Diffstat (limited to 'Bugzilla/Bug.pm')
-rw-r--r--Bugzilla/Bug.pm21
1 files changed, 17 insertions, 4 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 6973ae2fc..6c23d6992 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -333,10 +333,14 @@ sub new {
# If we get something that looks like a word (not a number),
# make it the "name" param.
- if (!defined $param || (!ref($param) && $param !~ /^\d+$/)) {
+ if (!defined $param
+ || (!ref($param) && $param =~ /\D/)
+ || (ref($param) && $param->{id} =~ /\D/))
+ {
# But only if aliases are enabled.
if (Bugzilla->params->{'usebugaliases'} && $param) {
- $param = { name => $param };
+ $param = { name => ref($param) ? $param->{id} : $param,
+ cache => ref($param) ? $param->{cache} : 0 };
}
else {
# Aliases are off, and we got something that's not a number.
@@ -370,6 +374,13 @@ sub new {
return $self;
}
+sub cache_key {
+ my $class = shift;
+ my $key = $class->SUPER::cache_key(@_)
+ || return;
+ return $key . ',' . Bugzilla->user->id;
+}
+
sub check {
my $class = shift;
my ($id, $field) = @_;
@@ -3241,7 +3252,8 @@ sub component_obj {
my ($self) = @_;
return $self->{component_obj} if defined $self->{component_obj};
return {} if $self->{error};
- $self->{component_obj} = new Bugzilla::Component($self->{component_id});
+ $self->{component_obj} =
+ new Bugzilla::Component({ id => $self->{component_id}, cache => 1 });
return $self->{component_obj};
}
@@ -3410,7 +3422,8 @@ sub product {
sub product_obj {
my $self = shift;
return {} if $self->{error};
- $self->{product_obj} ||= new Bugzilla::Product($self->{product_id});
+ $self->{product_obj} ||=
+ new Bugzilla::Product({ id => $self->{product_id}, cache => 1 });
return $self->{product_obj};
}