diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /lib/gitlab/whats_new.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'lib/gitlab/whats_new.rb')
-rw-r--r-- | lib/gitlab/whats_new.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/gitlab/whats_new.rb b/lib/gitlab/whats_new.rb index e95ace2c475..69ccb48c544 100644 --- a/lib/gitlab/whats_new.rb +++ b/lib/gitlab/whats_new.rb @@ -2,27 +2,39 @@ module Gitlab module WhatsNew - CACHE_DURATION = 1.day + CACHE_DURATION = 1.hour WHATS_NEW_FILES_PATH = Rails.root.join('data', 'whats_new', '*.yml') private - def whats_new_most_recent_release_items - Rails.cache.fetch('whats_new:release_items', expires_in: CACHE_DURATION) do - file = File.read(most_recent_release_file_path) + def whats_new_release_items(page: 1) + Rails.cache.fetch(whats_new_items_cache_key(page), expires_in: CACHE_DURATION) do + index = page - 1 + file_path = whats_new_file_paths[index] + + next if file_path.nil? + + file = File.read(file_path) items = YAML.safe_load(file, permitted_classes: [Date]) items if items.is_a?(Array) end rescue => e - Gitlab::ErrorTracking.track_exception(e, yaml_file_path: most_recent_release_file_path) + Gitlab::ErrorTracking.track_exception(e, page: page) nil end - def most_recent_release_file_path - @most_recent_release_file_path ||= Dir.glob(WHATS_NEW_FILES_PATH).max + def whats_new_file_paths + @whats_new_file_paths ||= Rails.cache.fetch('whats_new:file_paths', expires_in: CACHE_DURATION) do + Dir.glob(WHATS_NEW_FILES_PATH).sort.reverse + end + end + + def whats_new_items_cache_key(page) + filename = /\d*\_\d*\_\d*/.match(whats_new_file_paths&.first) + "whats_new:release_items:file-#{filename}:page-#{page}" end end end |