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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-31 18:08:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-31 18:08:50 +0300
commitccab6fb4df8bc12220334618e56d911c4d0e447c (patch)
treea8c7bb66fb4c36c97e7e1b4f27744fcd93c3bcf3 /lib/gitlab/utils
parent820c5f6d5c816ba4b742f2ae2e08cc548314531a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/utils')
-rw-r--r--lib/gitlab/utils/error_message.rb8
-rw-r--r--lib/gitlab/utils/strong_memoize.rb21
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/gitlab/utils/error_message.rb b/lib/gitlab/utils/error_message.rb
index e9c6f8a5847..72b69fb078f 100644
--- a/lib/gitlab/utils/error_message.rb
+++ b/lib/gitlab/utils/error_message.rb
@@ -5,8 +5,14 @@ module Gitlab
module ErrorMessage
extend self
+ UF_ERROR_PREFIX = 'UF'
+
def to_user_facing(message)
- "UF: #{message}"
+ prefixed_error_message(message, UF_ERROR_PREFIX)
+ end
+
+ def prefixed_error_message(message, prefix)
+ "#{prefix}: #{message}"
end
end
end
diff --git a/lib/gitlab/utils/strong_memoize.rb b/lib/gitlab/utils/strong_memoize.rb
index eb44b7ddd95..2b3841b8f09 100644
--- a/lib/gitlab/utils/strong_memoize.rb
+++ b/lib/gitlab/utils/strong_memoize.rb
@@ -35,6 +35,27 @@ module Gitlab
end
end
+ # Works the same way as "strong_memoize" but takes
+ # a second argument - expire_in. This allows invalidate
+ # the data after specified number of seconds
+ def strong_memoize_with_expiration(name, expire_in)
+ key = ivar(name)
+ expiration_key = "#{key}_expired_at"
+
+ if instance_variable_defined?(expiration_key)
+ expire_at = instance_variable_get(expiration_key)
+ clear_memoization(name) if Time.current > expire_at
+ end
+
+ if instance_variable_defined?(key)
+ instance_variable_get(key)
+ else
+ value = instance_variable_set(key, yield)
+ instance_variable_set(expiration_key, Time.current + expire_in)
+ value
+ end
+ end
+
def strong_memoize_with(name, *args)
container = strong_memoize(name) { {} }