diff options
Diffstat (limited to 'lib/gitlab/ci/build')
-rw-r--r-- | lib/gitlab/ci/build/artifacts/expire_in_parser.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/ci/build/rules/rule/clause/changes.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/build/rules/rule/clause/if.rb | 2 |
3 files changed, 19 insertions, 5 deletions
diff --git a/lib/gitlab/ci/build/artifacts/expire_in_parser.rb b/lib/gitlab/ci/build/artifacts/expire_in_parser.rb index 3e8a1fb86fc..848208c5cdd 100644 --- a/lib/gitlab/ci/build/artifacts/expire_in_parser.rb +++ b/lib/gitlab/ci/build/artifacts/expire_in_parser.rb @@ -16,9 +16,7 @@ module Gitlab def validate_duration return true if never? - parse - rescue ChronicDuration::DurationParseError - false + cached_parse end def seconds_from_now @@ -29,12 +27,28 @@ module Gitlab attr_reader :value + def cached_parse + return validation_cache[value] if validation_cache.key?(value) + + validation_cache[value] = safe_parse + end + + def safe_parse + parse + rescue ChronicDuration::DurationParseError + false + end + def parse return if never? ChronicDuration.parse(value) end + def validation_cache + Gitlab::SafeRequestStore[:ci_expire_in_parser_cache] ||= {} + end + def never? value.to_s.casecmp('never') == 0 end diff --git a/lib/gitlab/ci/build/rules/rule/clause/changes.rb b/lib/gitlab/ci/build/rules/rule/clause/changes.rb index 82a59fdb4e1..4c5f02b4f7b 100644 --- a/lib/gitlab/ci/build/rules/rule/clause/changes.rb +++ b/lib/gitlab/ci/build/rules/rule/clause/changes.rb @@ -9,7 +9,7 @@ module Gitlab end def satisfied_by?(pipeline, context) - return true if pipeline.modified_paths.nil? + return true unless pipeline&.modified_paths expanded_globs = expand_globs(context) pipeline.modified_paths.any? do |path| diff --git a/lib/gitlab/ci/build/rules/rule/clause/if.rb b/lib/gitlab/ci/build/rules/rule/clause/if.rb index 499a265a1e2..dd131448287 100644 --- a/lib/gitlab/ci/build/rules/rule/clause/if.rb +++ b/lib/gitlab/ci/build/rules/rule/clause/if.rb @@ -8,7 +8,7 @@ module Gitlab @expression = expression end - def satisfied_by?(pipeline, context) + def satisfied_by?(_pipeline, context) ::Gitlab::Ci::Pipeline::Expression::Statement.new( @expression, context.variables_hash).truthful? end |