Skip to content

Commit 045226a

Browse files
Fix a bug that was causing a huge amount of calls to git APIs
`format_path` is called for each warning/error discovered, and that the method is creating a new instance of the git source plugin at each invocation. This prevent the plugin from caching any data and, in the case of gitlab at least, means we're hitting the API repeatedly for each warning just to grab the project base URL. In my case this meant 1000+ calls to the GitLab API which caused a large delay. This change caches the git plugin on an instance variable so that we don't need to create it every time.
1 parent 020d670 commit 045226a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/xcode_summary/plugin.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ def inline_mode
9898
def ignores_warnings
9999
@ignores_warnings || false
100100
end
101+
102+
def plugin
103+
# Pick a Dangerfile plugin for a chosen request_source
104+
# based on https://github.com/danger/danger/blob/master/lib/danger/plugin_support/plugin.rb#L31
105+
plugins = Plugin.all_plugins.select { |plugin| Dangerfile.essential_plugin_classes.include? plugin }
106+
@plugin ||= plugins.select { |p| p.method_defined? :html_link }.map { |p| p.new(@dangerfile) }.compact.first
107+
end
101108
# rubocop:enable Lint/DuplicateMethods
102109

103110
# Reads a file with JSON Xcode summary and reports it.
@@ -210,11 +217,6 @@ def parse_test_location(failure)
210217
end
211218

212219
def format_path(path)
213-
# Pick a Dangerfile plugin for a chosen request_source
214-
# based on https://github.com/danger/danger/blob/master/lib/danger/plugin_support/plugin.rb#L31
215-
plugins = Plugin.all_plugins.select { |plugin| Dangerfile.essential_plugin_classes.include? plugin }
216-
plugin = plugins.select { |p| p.method_defined? :html_link }.map { |p| p.new(@dangerfile) }.compact.first
217-
218220
if plugin
219221
clean_path, line = parse_filename(path)
220222
path = clean_path + '#L' + line if clean_path && line

0 commit comments

Comments
 (0)