2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module WhatsNew
|
2021-01-29 00:20:46 +05:30
|
|
|
CACHE_DURATION = 1.hour
|
2021-01-03 14:25:43 +05:30
|
|
|
WHATS_NEW_FILES_PATH = Rails.root.join('data', 'whats_new', '*.yml')
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
items = YAML.safe_load(file, permitted_classes: [Date])
|
|
|
|
|
|
|
|
items if items.is_a?(Array)
|
|
|
|
end
|
|
|
|
rescue => e
|
2021-01-29 00:20:46 +05:30
|
|
|
Gitlab::ErrorTracking.track_exception(e, page: page)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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}"
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|