summaryrefslogtreecommitdiff
path: root/app/models/broadcast_message.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-02 15:06:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-02 15:06:36 +0000
commit556c79d6cc3d7b24ecbba3a79f8432eb3fcf5c7e (patch)
tree93c84c603316cdee73ce85949ba70e29ef78af32 /app/models/broadcast_message.rb
parentbffcdf9bca11a4d43cc40e3f382f03088d36f7c6 (diff)
downloadgitlab-ce-556c79d6cc3d7b24ecbba3a79f8432eb3fcf5c7e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/broadcast_message.rb')
-rw-r--r--app/models/broadcast_message.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb
index dfcf28763ee..9c2ae92071d 100644
--- a/app/models/broadcast_message.rb
+++ b/app/models/broadcast_message.rb
@@ -20,7 +20,7 @@ class BroadcastMessage < ApplicationRecord
after_commit :flush_redis_cache
- def self.current
+ def self.current(current_path = nil)
messages = cache.fetch(CACHE_KEY, as: BroadcastMessage, expires_in: cache_expires_in) do
current_and_future_messages
end
@@ -33,7 +33,7 @@ class BroadcastMessage < ApplicationRecord
# cache so we don't keep running this code all the time.
cache.expire(CACHE_KEY) if now_or_future.empty?
- now_or_future.select(&:now?)
+ now_or_future.select(&:now?).select { |message| message.matches_current_path(current_path) }
end
def self.current_and_future_messages
@@ -72,6 +72,12 @@ class BroadcastMessage < ApplicationRecord
now? || future?
end
+ def matches_current_path(current_path)
+ return true if current_path.blank? || target_path.blank?
+
+ current_path.match(Regexp.escape(target_path).gsub('\\*', '.*'))
+ end
+
def flush_redis_cache
self.class.cache.expire(CACHE_KEY)
end