Skip to content

Commit f0b8f4f

Browse files
committed
Bug 1446236 - Add & use simpler method to check if an extension is present (#35)
1 parent f344c52 commit f0b8f4f

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

Bugzilla.pm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ sub template_inner {
125125
}
126126

127127
sub extensions {
128+
# Guard against extensions querying the extension list during initialization
129+
# (through this method or has_extension).
130+
# The extension list is not fully populated at that point,
131+
# so the results would not be meaningful.
132+
state $recursive = 0;
133+
die "Recursive attempt to load/query extensions" if $recursive;
134+
$recursive = 1;
135+
128136
state $extensions;
129137
return $extensions if $extensions;
130138
my $extension_packages = Bugzilla::Extension->load_all();
@@ -134,9 +142,20 @@ sub extensions {
134142
push @$extensions, $package;
135143
}
136144
}
145+
$recursive = 0;
137146
return $extensions;
138147
}
139148

149+
sub has_extension {
150+
my ($class, $name) = @_;
151+
my $cache = $class->request_cache;
152+
if (!$cache->{extensions_hash}) {
153+
my %extensions = map { $_->NAME => 1 } @{Bugzilla->extensions};
154+
$cache->{extensions_hash} = \%extensions;
155+
}
156+
return exists $cache->{extensions_hash}{$name};
157+
}
158+
140159
sub cgi {
141160
return request_cache->{cgi} ||= Bugzilla::CGI->new;
142161
}

Bugzilla/Search.pm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use Date::Format;
3434
use Date::Parse;
3535
use Scalar::Util qw(blessed);
3636
use List::MoreUtils qw(all firstidx part uniq);
37-
use List::Util qw(any);
3837
use POSIX qw(INT_MAX);
3938
use Storable qw(dclone);
4039
use Time::HiRes qw(gettimeofday tv_interval);
@@ -803,9 +802,7 @@ sub data {
803802
# BMO - to avoid massive amounts of joins, if we're selecting a lot of
804803
# tracking flags, replace them with placeholders. the values will be
805804
# retrieved later and injected into the result.
806-
state $have_tracking_flags
807-
= any { $_->NAME eq 'TrackingFlags' } @{Bugzilla->extensions};
808-
if ($have_tracking_flags) {
805+
if (Bugzilla->has_extension('TrackingFlags')) {
809806
my %tf_map = map { $_ => 1 } Bugzilla->tracking_flag_names;
810807
my @tf_selected = grep { exists $tf_map{$_} } @orig_fields;
811808

@@ -874,7 +871,7 @@ sub data {
874871
$self->{data} = [map { $data{$_} } @$bug_ids];
875872

876873
# BMO - get tracking flags values, and insert into result
877-
if ($have_tracking_flags && @{$self->{tracking_flags}}) {
874+
if (Bugzilla->has_extension('TrackingFlags') && @{$self->{tracking_flags}}) {
878875

879876
# read values
880877
my $values;

extensions/BugModal/Extension.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ sub template_before_process {
197197
return if exists $bug->{error};
198198

199199
# trigger loading of tracking flags
200-
state $have_tracking_flags
201-
= any { $_->NAME eq 'TrackingFlags' } @{Bugzilla->extensions};
202-
if ($have_tracking_flags) {
200+
if (Bugzilla->has_extension('TrackingFlags')) {
203201
Bugzilla::Extension::TrackingFlags->template_before_process({
204202
file => 'bug/edit.html.tmpl', vars => $vars,
205203
});

votes.cgi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use lib qw(. lib local/lib/perl5);
3030
use Bugzilla;
3131
use Bugzilla::Error;
3232

33-
my $is_enabled = grep { $_->NAME eq 'Voting' } @{Bugzilla->extensions};
34-
$is_enabled || ThrowCodeError('extension_disabled', {name => 'Voting'});
33+
Bugzilla->has_extension('Voting') || ThrowCodeError('extension_disabled', { name => 'Voting' });
3534

3635
my $cgi = Bugzilla->cgi;
3736
my $action = $cgi->param('action') || 'show_user';

0 commit comments

Comments
 (0)