-
-
Notifications
You must be signed in to change notification settings - Fork 28
Bug 1446236 - Add & use simpler method to check if an extension is present #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ba55018
537dfba
352401c
df7fde8
9e3deeb
4deaf55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,6 +233,15 @@ sub template_inner { | |
|
||
sub extensions { | ||
my ($class) = @_; | ||
|
||
# Guard against extensions querying the extension list during initialization | ||
# (through this method or has_extension). | ||
# The extension list is not fully populated at that point, | ||
# so the results would not be meaningful. | ||
state $recursive = 0; | ||
die "Recursive attempt to load/query extensions" if $recursive; | ||
$recursive = 1; | ||
|
||
my $cache = $class->request_cache; | ||
if (!$cache->{extensions}) { | ||
my $extension_packages = Bugzilla::Extension->load_all(); | ||
|
@@ -245,9 +254,20 @@ sub extensions { | |
} | ||
$cache->{extensions} = \@extensions; | ||
} | ||
$recursive = 0; | ||
return $cache->{extensions}; | ||
} | ||
|
||
sub has_extension { | ||
my ($class, $name) = @_; | ||
my $cache = $class->request_cache; | ||
if (!$cache->{extensions_hash}) { | ||
my %extensions = map { $_->NAME => 1 } @{ Bugzilla->extensions }; | ||
$cache->{extensions_hash} = \%extensions; | ||
} | ||
return exists $cache->{extensions_hash}{$name}; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is something wrong with this implementation, but I'm not sure yet what. After the hash is built, it contains only two elements on successive requests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That suggests to me there should be a test to capture correctness in extensions, which I gather this change would fail (and prompt an investigation of why). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured out the problem, it was caused by a change in another pull request of mine. |
||
sub cgi { | ||
return $_[0]->request_cache->{cgi} ||= new Bugzilla::CGI(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you are guarding against a recursive call. That at least needs a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some explanation in the commit message. Essentially it's an extension checking
Bugzilla->extensions
during its initialization, which is invalid as the extension list is still being constructed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Looking at it now, my gut says it might not work completely right. I'd have thought it was more idiomatic to use not a
state
var, but amy
var outside the sub, and uselocal
to set the guard variable straight after the check, in order to use dynamic scoping rather than lexical.