Commit 577be505 authored by Peter Leitzen's avatar Peter Leitzen

Mark feature flags in Gitlab/MarkUsedFeatureFlags only once

Mark dynamic feature flags and feature flags for usage data counters
only once per whole rubocop run instead of once per file.

This reduces the overall runtime of this cop drastically:

    time bundle exec rubocop -C false -f q --only Gitlab/MarkUsedFeatureFlags

* Before: ~8m53.589s
* After: ~3m56.036s
parent fa1c9710
......@@ -47,10 +47,21 @@ module RuboCop
:usage_data_static_site_editor_merge_requests # https://gitlab.com/gitlab-org/gitlab/-/issues/284083
].freeze
class << self
# We track feature flags in `on_new_investigation` only once per
# rubocop whole run instead once per file.
attr_accessor :feature_flags_already_tracked
end
# Called before all on_... have been called
# When refining this method, always call `super`
def on_new_investigation
super
return if self.class.feature_flags_already_tracked
self.class.feature_flags_already_tracked = true
track_dynamic_feature_flags!
track_usage_data_counters_known_events!
end
......
......@@ -16,6 +16,7 @@ RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do
stub_const("#{described_class}::DYNAMIC_FEATURE_FLAGS", [])
allow(cop).to receive(:defined_feature_flags).and_return(defined_feature_flags)
allow(cop).to receive(:usage_data_counters_known_event_feature_flags).and_return([])
described_class.feature_flags_already_tracked = false
end
def feature_flag_path(feature_flag_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment