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/tree_summary.rb')
-rw-r--r--lib/gitlab/tree_summary.rb36
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/gitlab/tree_summary.rb b/lib/gitlab/tree_summary.rb
index 5df53b5adde..4ec43e62c19 100644
--- a/lib/gitlab/tree_summary.rb
+++ b/lib/gitlab/tree_summary.rb
@@ -2,21 +2,24 @@
module Gitlab
class TreeSummary
- prepend_if_ee('::EE::Gitlab::TreeSummary') # rubocop: disable Cop/InjectEnterpriseEditionModule
-
include ::Gitlab::Utils::StrongMemoize
+ include ::MarkupHelper
+
+ CACHE_EXPIRE_IN = 1.hour
+ MAX_OFFSET = 2**31
- attr_reader :commit, :project, :path, :offset, :limit
+ attr_reader :commit, :project, :path, :offset, :limit, :user
attr_reader :resolved_commits
private :resolved_commits
- def initialize(commit, project, params = {})
+ def initialize(commit, project, user, params = {})
@commit = commit
@project = project
+ @user = user
@path = params.fetch(:path, nil).presence
- @offset = params.fetch(:offset, 0).to_i
+ @offset = [params.fetch(:offset, 0).to_i, MAX_OFFSET].min
@limit = (params.fetch(:limit, 25) || 25).to_i
# Ensure that if multiple tree entries share the same last commit, they share
@@ -43,6 +46,17 @@ module Gitlab
[summary, commits]
end
+ def fetch_logs
+ cache_key = ['projects', project.id, 'logs', commit.id, path, offset]
+ Rails.cache.fetch(cache_key, expires_in: CACHE_EXPIRE_IN) do
+ logs, _ = summarize
+
+ new_offset = next_offset if more?
+
+ [logs.as_json, new_offset]
+ end
+ end
+
# Does the tree contain more entries after the given offset + limit?
def more?
all_contents[next_offset].present?
@@ -84,6 +98,7 @@ module Gitlab
end
commits_hsh = repository.list_last_commits_for_tree(commit.id, ensured_path, offset: offset, limit: limit)
+ prerender_commit_full_titles!(commits_hsh.values)
entries.each do |entry|
path_key = entry_path(entry)
@@ -92,6 +107,7 @@ module Gitlab
if commit
entry[:commit] = commit
entry[:commit_path] = commit_path(commit)
+ entry[:commit_title_html] = markdown_field(commit, :full_title)
end
end
end
@@ -119,5 +135,15 @@ module Gitlab
def tree
strong_memoize(:tree) { repository.tree(commit.id, path) }
end
+
+ def prerender_commit_full_titles!(commits)
+ # Preload commit authors as they are used in rendering
+ commits.each(&:lazy_author)
+
+ renderer = Banzai::ObjectRenderer.new(user: user, default_project: project)
+ renderer.render(commits, :full_title)
+ end
end
end
+
+Gitlab::TreeSummary.prepend_if_ee('::EE::Gitlab::TreeSummary')