diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/gitlab/ci/build/artifacts/expire_in_parser.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'lib/gitlab/ci/build/artifacts/expire_in_parser.rb')
-rw-r--r-- | lib/gitlab/ci/build/artifacts/expire_in_parser.rb | 20 |
1 files changed, 17 insertions, 3 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 |