summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Bug.pm
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2012-11-22 15:39:05 +0100
committerByron Jones <bjones@mozilla.com>2012-11-22 15:39:05 +0100
commit4c3e00573133dfc53d07805629af19599aaef7df (patch)
treee9ce090e958fb60edee1656af12fa414ba79efc3 /Bugzilla/Bug.pm
parentda12cec61f8c7e667b00fc5fc39c827d3593f021 (diff)
downloadbugzilla-4c3e00573133dfc53d07805629af19599aaef7df.tar.gz
bugzilla-4c3e00573133dfc53d07805629af19599aaef7df.tar.xz
Bug 811280: Adds a caching mechanism to Bugzilla::Object to avoid querying the database repeatedly for the same information
r=dkl,a=LpSolit
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 4a1723754..b72a8fcdb 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -318,9 +318,13 @@ 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/))
+ {
if ($param) {
- $param = { name => $param };
+ $param = { name => ref($param) ? $param->{id} : $param,
+ cache => ref($param) ? $param->{cache} : 0 };
}
else {
# We got something that's not a number.
@@ -354,6 +358,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) = @_;
@@ -3216,7 +3227,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};
}
@@ -3424,7 +3436,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};
}