Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/build/artifacts/expire_in_parser.rb')
-rw-r--r--lib/gitlab/ci/build/artifacts/expire_in_parser.rb20
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