From 64891c6c40c6b670c2b50aab8ba56e3d47e30076 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 21 Mar 2015 23:48:08 -0700 Subject: Replace commits calendar with contributions calendar * count opening of issues and merge requests * dont trigger git repository - use events from database * much-much faster since does not affected by repository size --- app/controllers/users_controller.rb | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 68130eb128c..f39c820626f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -31,9 +31,7 @@ class UsersController < ApplicationController end def calendar - projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) - - calendar = Gitlab::CommitsCalendar.new(projects, @user) + calendar = contributions_calendar @timestamps = calendar.timestamps @starting_year = calendar.starting_year @starting_month = calendar.starting_month @@ -42,20 +40,13 @@ class UsersController < ApplicationController end def calendar_activities - projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) + @calendar_date = Date.parse(params[:date]) rescue nil + @events = [] - date = Date.parse(params[:date]) rescue nil - if date - @calendar_activities = Gitlab::CommitsCalendar.get_commits_for_date(projects, @user, date) - else - @calendar_activities = {} + if @calendar_date + @events = contributions_calendar.events_by_date(@calendar_date) end - # get the total number of unique commits - @commit_count = @calendar_activities.values.flatten.map(&:id).uniq.count - - @calendar_date = date - render 'calendar_activities', layout: false end @@ -82,4 +73,14 @@ class UsersController < ApplicationController @authorized_projects_ids ||= ProjectsFinder.new.execute(current_user).pluck(:id) end + + def contributed_projects + @contributed_projects = Project. + where(id: authorized_projects_ids & @user.contributed_projects_ids).reject(&:forked?) + end + + def contributions_calendar + @contributions_calendar ||= Gitlab::ContributionsCalendar. + new(contributed_projects, @user) + end end -- cgit v1.2.1 From 43afe46bbd19b1edf60abf3f104fb2b0d29af564 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 13:55:00 -0700 Subject: Refactor contributions events and write tests for calendar --- app/controllers/users_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f39c820626f..f9b568b8af9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,10 +4,7 @@ class UsersController < ApplicationController layout :determine_layout def show - @contributed_projects = Project. - where(id: authorized_projects_ids & @user.contributed_projects_ids). - in_group_namespace. - includes(:namespace). + @contributed_projects = contributed_projects.joined(@user). reject(&:forked?) @projects = @user.personal_projects. @@ -76,11 +73,12 @@ class UsersController < ApplicationController def contributed_projects @contributed_projects = Project. - where(id: authorized_projects_ids & @user.contributed_projects_ids).reject(&:forked?) + where(id: authorized_projects_ids & @user.contributed_projects_ids). + includes(:namespace) end def contributions_calendar @contributions_calendar ||= Gitlab::ContributionsCalendar. - new(contributed_projects, @user) + new(contributed_projects.reject(&:forked?), @user) end end -- cgit v1.2.1