Commit a5267967 authored by Nick Thomas's avatar Nick Thomas

Merge branch '209912-commits-markdown-cache-preload' into 'master'

Preload commits markdown cache

See merge request gitlab-org/gitlab!35314
parents b2833169 5b677ab4
...@@ -109,8 +109,8 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo ...@@ -109,8 +109,8 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
# or from cache if already merged # or from cache if already merged
@commits = @commits =
set_commits_for_rendering( set_commits_for_rendering(
@merge_request.recent_commits.with_latest_pipeline(@merge_request.source_branch), @merge_request.recent_commits.with_latest_pipeline(@merge_request.source_branch).with_markdown_cache,
commits_count: @merge_request.commits_count commits_count: @merge_request.commits_count
) )
render json: { html: view_to_html_string('projects/merge_requests/_commits') } render json: { html: view_to_html_string('projects/merge_requests/_commits') }
......
...@@ -53,6 +53,17 @@ class CommitCollection ...@@ -53,6 +53,17 @@ class CommitCollection
self self
end end
# Returns the collection with markdown fields preloaded.
#
# Get the markdown cache from redis using pipeline to prevent n+1 requests
# when rendering the markdown of an attribute (e.g. title, full_title,
# description).
def with_markdown_cache
Commit.preload_markdown_cache!(commits)
self
end
def unenriched def unenriched
commits.reject(&:gitaly_commit?) commits.reject(&:gitaly_commit?)
end end
......
---
title: Preload commits markdown cache
merge_request: 35314
author:
type: performance
...@@ -75,6 +75,18 @@ RSpec.describe CommitCollection do ...@@ -75,6 +75,18 @@ RSpec.describe CommitCollection do
end end
end end
describe '#with_markdown_cache' do
let(:commits) { [commit] }
let(:collection) { described_class.new(project, commits) }
it 'preloads commits cache markdown' do
aggregate_failures do
expect(Commit).to receive(:preload_markdown_cache!).with(commits)
expect(collection.with_markdown_cache).to eq(collection)
end
end
end
describe 'enrichment methods' do describe 'enrichment methods' do
let(:gitaly_commit) { commit } let(:gitaly_commit) { commit }
let(:hash_commit) { Commit.from_hash(gitaly_commit.to_hash, project) } let(:hash_commit) { Commit.from_hash(gitaly_commit.to_hash, project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment