Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve "DashboardController#activity.json is slow due to SQL"
- Loading branch information
Francisco Javier López
authored and
Douwe Maan
committed
Nov 6, 2017
1 parent
34a205b
commit bf0331d
Showing
36 changed files
with
429 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class BaseRenderer | ||
attr_reader :current_user | ||
|
||
def initialize(current_user = nil) | ||
@current_user = current_user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Events | ||
class RenderService < BaseRenderer | ||
def execute(events, atom_request: false) | ||
events.map(&:note).compact.group_by(&:project).each do |project, notes| | ||
render_notes(notes, project, atom_request) | ||
end | ||
end | ||
|
||
private | ||
|
||
def render_notes(notes, project, atom_request) | ||
Notes::RenderService.new(current_user).execute(notes, project, render_options(atom_request)) | ||
end | ||
|
||
def render_options(atom_request) | ||
return {} unless atom_request | ||
|
||
{ only_path: false, xhtml: true } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Notes | ||
class RenderService < BaseRenderer | ||
# Renders a collection of Note instances. | ||
# | ||
# notes - The notes to render. | ||
# project - The project to use for redacting. | ||
# user - The user viewing the notes. | ||
|
||
# Possible options: | ||
# requested_path - The request path. | ||
# project_wiki - The project's wiki. | ||
# ref - The current Git reference. | ||
# only_path - flag to turn relative paths into absolute ones. | ||
# xhtml - flag to save the html in XHTML | ||
def execute(notes, project, **opts) | ||
renderer = Banzai::ObjectRenderer.new(project, current_user, **opts) | ||
|
||
renderer.render(notes, :note) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
%div{ xmlns: "http://www.w3.org/1999/xhtml" } | ||
= markdown(note.note, pipeline: :atom, project: note.project, author: note.author) | ||
= markdown_field(note, :note) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
changelogs/unreleased/27375-dashboard-activity-performance.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Improve DashboardController#activity.json performance | ||
merge_request: 14985 | ||
author: | ||
type: performance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'uri' | ||
|
||
module Banzai | ||
module Filter | ||
# HTML filter that converts relative urls into absolute ones. | ||
class AbsoluteLinkFilter < HTML::Pipeline::Filter | ||
def call | ||
return doc unless context[:only_path] == false | ||
|
||
doc.search('a.gfm').each do |el| | ||
process_link_attr el.attribute('href') | ||
end | ||
|
||
doc | ||
end | ||
|
||
protected | ||
|
||
def process_link_attr(html_attr) | ||
return if html_attr.blank? | ||
return if html_attr.value.start_with?('//') | ||
|
||
uri = URI(html_attr.value) | ||
html_attr.value = absolute_link_attr(uri) if uri.relative? | ||
rescue URI::Error | ||
# noop | ||
end | ||
|
||
def absolute_link_attr(uri) | ||
URI.join(Gitlab.config.gitlab.url, uri).to_s | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.