diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-02-18 21:11:37 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-02-18 21:11:37 +0300 |
commit | 057d43500b1d0a9cb1d9905d776b1602dd3d3461 (patch) | |
tree | e287ef699915c861c036e6ef75829f90475cf49b /app | |
parent | 544596681a79e5be1aa631c6c36b47072807f9e8 (diff) | |
parent | 63f11a68c5e9edf36d062bd4f029d81a0861ef82 (diff) |
Merge branch 'performance-improvements' into 'master'
Performance improvements
* More efficient DB queries
* Cache ApplicationSettings per request
* Dont query for objects you dont need
See merge request !1540
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/dashboard_controller.rb | 24 | ||||
-rw-r--r-- | app/controllers/groups_controller.rb | 26 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 7 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 8 | ||||
-rw-r--r-- | app/models/event.rb | 1 | ||||
-rw-r--r-- | app/views/dashboard/_activities.html.haml | 7 | ||||
-rw-r--r-- | app/views/dashboard/_project.html.haml | 2 | ||||
-rw-r--r-- | app/views/groups/_projects.html.haml | 2 | ||||
-rw-r--r-- | app/views/groups/show.html.haml | 5 | ||||
-rw-r--r-- | app/views/projects/_home_panel.html.haml | 2 |
11 files changed, 61 insertions, 36 deletions
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 9e59264e418..eca7b39bcdf 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -12,11 +12,7 @@ class DashboardController < ApplicationController @groups = current_user.authorized_groups.order_name_asc @has_authorized_projects = @projects.count > 0 @projects_count = @projects.count - @projects = @projects.limit(@projects_limit) - - @events = Event.in_projects(current_user.authorized_projects.pluck(:id)) - @events = @event_filter.apply_filter(@events) - @events = @events.limit(20).offset(params[:offset] || 0) + @projects = @projects.includes(:namespace).limit(@projects_limit) @last_push = current_user.recent_push @@ -24,8 +20,16 @@ class DashboardController < ApplicationController respond_to do |format| format.html - format.json { pager_json("events/_events", @events.count) } - format.atom { render layout: false } + + format.json do + load_events + pager_json("events/_events", @events.count) + end + + format.atom do + load_events + render layout: false + end end end @@ -74,4 +78,10 @@ class DashboardController < ApplicationController def load_projects @projects = current_user.authorized_projects.sorted_by_activity.non_archived end + + def load_events + @events = Event.in_projects(current_user.authorized_projects.pluck(:id)) + @events = @event_filter.apply_filter(@events).with_associations + @events = @events.limit(20).offset(params[:offset] || 0) + end end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index aad3709090e..d011523c94f 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -10,11 +10,11 @@ class GroupsController < ApplicationController # Load group projects before_filter :load_projects, except: [:new, :create, :projects, :edit, :update] + before_filter :event_filter, only: :show + before_filter :set_title, only: [:new, :create] layout :determine_layout - before_filter :set_title, only: [:new, :create] - def new @group = Group.new end @@ -32,15 +32,21 @@ class GroupsController < ApplicationController end def show - @events = Event.in_projects(project_ids) - @events = event_filter.apply_filter(@events) - @events = @events.limit(20).offset(params[:offset] || 0) @last_push = current_user.recent_push if current_user + @projects = @projects.includes(:namespace) respond_to do |format| format.html - format.json { pager_json("events/_events", @events.count) } - format.atom { render layout: false } + + format.json do + load_events + pager_json("events/_events", @events.count) + end + + format.atom do + load_events + render layout: false + end end end @@ -149,4 +155,10 @@ class GroupsController < ApplicationController def group_params params.require(:group).permit(:name, :description, :path, :avatar) end + + def load_events + @events = Event.in_projects(project_ids) + @events = event_filter.apply_filter(@events).with_associations + @events = @events.limit(20).offset(params[:offset] || 0) + end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 462ab3d4749..b0fde88babc 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -5,9 +5,10 @@ class ProjectsController < ApplicationController # Authorize before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive] + before_filter :set_title, only: [:new, :create] + before_filter :event_filter, only: :show layout 'navless', only: [:new, :create, :fork] - before_filter :set_title, only: [:new, :create] def new @project = Project.new @@ -56,9 +57,6 @@ class ProjectsController < ApplicationController end limit = (params[:limit] || 20).to_i - @events = @project.events.recent - @events = event_filter.apply_filter(@events) - @events = @events.limit(limit).offset(params[:offset] || 0) @show_star = !(current_user && current_user.starred?(@project)) @@ -76,7 +74,12 @@ class ProjectsController < ApplicationController end end - format.json { pager_json('events/_events', @events.count) } + format.json do + @events = @project.events.recent + @events = event_filter.apply_filter(@events).with_associations + @events = @events.limit(limit).offset(params[:offset] || 0) + pager_json('events/_events', @events.count) + end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e4f588c6a60..8c5605c8b4b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,17 +9,18 @@ class UsersController < ApplicationController authorized_projects_ids = visible_projects.pluck(:id) @contributed_projects = Project.where(id: authorized_projects_ids). - in_group_namespace + in_group_namespace.includes(:namespace) @projects = @user.personal_projects. - where(id: authorized_projects_ids) + where(id: authorized_projects_ids).includes(:namespace) # Collect only groups common for both users @groups = @user.groups & GroupsFinder.new.execute(current_user) # Get user activity feed for projects common for both users @events = @user.recent_events. - where(project_id: authorized_projects_ids).limit(30) + where(project_id: authorized_projects_ids). + with_associations.limit(30) @title = @user.name @title_url = user_path(@user) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e45f4650309..f65c5335a62 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -51,7 +51,13 @@ module ApplicationHelper end def project_icon(project_id, options = {}) - project = Project.find_with_namespace(project_id) + project = + if project_id.is_a?(Project) + project = project_id + else + Project.find_with_namespace(project_id) + end + if project.avatar.present? image_tag project.avatar.url, options elsif project.avatar_in_git diff --git a/app/models/event.rb b/app/models/event.rb index cae7f0be85b..5579ab1dbb0 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -47,6 +47,7 @@ class Event < ActiveRecord::Base scope :recent, -> { order("created_at DESC") } scope :code_push, -> { where(action: PUSHED) } scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } + scope :with_associations, -> { includes(project: :namespace) } class << self def reset_event_cache_for(target) diff --git a/app/views/dashboard/_activities.html.haml b/app/views/dashboard/_activities.html.haml index fdf96dd6f56..c1fc1602d0a 100644 --- a/app/views/dashboard/_activities.html.haml +++ b/app/views/dashboard/_activities.html.haml @@ -1,9 +1,4 @@ = render "events/event_last_push", event: @last_push = render 'shared/event_filter' - -- if @events.any? - .content_list -- else - .nothing-here-block Projects activity will be displayed here - +.content_list = spinner diff --git a/app/views/dashboard/_project.html.haml b/app/views/dashboard/_project.html.haml index f0fb2c1881b..fa9179cb249 100644 --- a/app/views/dashboard/_project.html.haml +++ b/app/views/dashboard/_project.html.haml @@ -1,6 +1,6 @@ = link_to project_path(project), class: dom_class(project) do .dash-project-avatar - = project_icon(project.to_param, alt: '', class: 'avatar project-avatar s40') + = project_icon(project, alt: '', class: 'avatar project-avatar s40') .dash-project-access-icon = visibility_level_icon(project.visibility_level) %span.str-truncated diff --git a/app/views/groups/_projects.html.haml b/app/views/groups/_projects.html.haml index a2f1d28a275..b505760fa8f 100644 --- a/app/views/groups/_projects.html.haml +++ b/app/views/groups/_projects.html.haml @@ -13,7 +13,7 @@ %li.project-row = link_to project_path(project), class: dom_class(project) do .dash-project-avatar - = project_icon(project.to_param, alt: '', class: 'avatar s40') + = project_icon(project, alt: '', class: 'avatar s40') .dash-project-access-icon = visibility_level_icon(project.visibility_level) %span.str-truncated diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index f2e591c1939..d5af859ee62 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -13,10 +13,7 @@ - if current_user = render "events/event_last_push", event: @last_push = render 'shared/event_filter' - - if @events.any? - .content_list - - else - .nothing-here-block Project activity will be displayed here + .content_list = spinner %aside.side.col-md-4 = render "projects", projects: @projects diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml index 5697f9ea1af..d8545dd2c85 100644 --- a/app/views/projects/_home_panel.html.haml +++ b/app/views/projects/_home_panel.html.haml @@ -1,7 +1,7 @@ - empty_repo = @project.empty_repo? .project-home-panel{:class => ("empty-project" if empty_repo)} .project-identicon-holder - = project_icon(@project.to_param, alt: '', class: 'avatar project-avatar') + = project_icon(@project, alt: '', class: 'avatar project-avatar') .project-home-row .project-home-desc - if @project.description.present? |