Commit 0ebc610e49b92d92e71aaea1ff664bcda121ff80

Authored by Dmitriy Zaporozhets
1 parent ac620363

Project activities perfomance increased. Cache for project activitites disabled.…

… Repository conception changed
app/assets/stylesheets/projects.css.scss
@@ -672,3 +672,17 @@ body.project-page h2.icon.loading { @@ -672,3 +672,17 @@ body.project-page h2.icon.loading {
672 } 672 }
673 } 673 }
674 } 674 }
  675 +
  676 +a.project-update.titled {
  677 + position: relative;
  678 + padding-right: 310px !important;
  679 +
  680 + .right-block {
  681 + padding: 10px;
  682 + width: 280px;
  683 + background: #f5f5f5;
  684 + position: absolute;
  685 + right: 0;
  686 + top: 0;
  687 + }
  688 +}
app/controllers/projects_controller.rb
@@ -69,7 +69,7 @@ class ProjectsController < ApplicationController @@ -69,7 +69,7 @@ class ProjectsController < ApplicationController
69 def show 69 def show
70 return render "projects/empty" unless @project.repo_exists? && @project.has_commits? 70 return render "projects/empty" unless @project.repo_exists? && @project.has_commits?
71 limit = (params[:limit] || 20).to_i 71 limit = (params[:limit] || 20).to_i
72 - @activities = @project.cached_updates(limit) 72 + @activities = @project.updates_wo_repo(limit)
73 end 73 end
74 74
75 def files 75 def files
app/controllers/repositories_controller.rb
@@ -9,7 +9,7 @@ class RepositoriesController < ApplicationController @@ -9,7 +9,7 @@ class RepositoriesController < ApplicationController
9 layout "project" 9 layout "project"
10 10
11 def show 11 def show
12 - @activities = @project.fresh_commits(20) 12 + @activities = @project.commits_with_refs(20)
13 end 13 end
14 14
15 def branches 15 def branches
app/models/commit.rb
@@ -2,6 +2,7 @@ class Commit @@ -2,6 +2,7 @@ class Commit
2 2
3 attr_accessor :commit 3 attr_accessor :commit
4 attr_accessor :head 4 attr_accessor :head
  5 + attr_accessor :refs
5 6
6 delegate :message, 7 delegate :message,
7 :committed_date, 8 :committed_date,
app/models/project.rb
@@ -79,6 +79,7 @@ class Project < ActiveRecord::Base @@ -79,6 +79,7 @@ class Project < ActiveRecord::Base
79 :repo_exists?, 79 :repo_exists?,
80 :commit, 80 :commit,
81 :commits, 81 :commits,
  82 + :commits_with_refs,
82 :tree, 83 :tree,
83 :heads, 84 :heads,
84 :commits_since, 85 :commits_since,
@@ -144,6 +145,10 @@ class Project < ActiveRecord::Base @@ -144,6 +145,10 @@ class Project < ActiveRecord::Base
144 users_projects.find_by_user_id(user_id) 145 users_projects.find_by_user_id(user_id)
145 end 146 end
146 147
  148 + def fresh_merge_requests(n)
  149 + merge_requests.includes(:project, :author).order("created_at desc").first(n)
  150 + end
  151 +
147 def fresh_issues(n) 152 def fresh_issues(n)
148 issues.includes(:project, :author).order("created_at desc").first(n) 153 issues.includes(:project, :author).order("created_at desc").first(n)
149 end 154 end
@@ -290,6 +295,16 @@ class Project < ActiveRecord::Base @@ -290,6 +295,16 @@ class Project < ActiveRecord::Base
290 end[0...n] 295 end[0...n]
291 end 296 end
292 297
  298 + def updates_wo_repo(n=3)
  299 + [
  300 + fresh_issues(n),
  301 + fresh_merge_requests(n),
  302 + fresh_notes(n)
  303 + ].compact.flatten.sort do |x, y|
  304 + y.created_at <=> x.created_at
  305 + end[0...n]
  306 + end
  307 +
293 def check_limit 308 def check_limit
294 unless owner.can_create_project? 309 unless owner.can_create_project?
295 errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it") 310 errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it")
app/models/repository.rb
@@ -112,6 +112,16 @@ class Repository @@ -112,6 +112,16 @@ class Repository
112 commits[0...n] 112 commits[0...n]
113 end 113 end
114 114
  115 + def commits_with_refs(n = 20)
  116 + commits = repo.refs.map { |ref| Commit.new(ref.commit, ref) }
  117 +
  118 + commits.sort! do |x, y|
  119 + y.committed_date <=> x.committed_date
  120 + end[0..n]
  121 +
  122 + commits
  123 + end
  124 +
115 def commits_since(date) 125 def commits_since(date)
116 commits = heads.map do |h| 126 commits = heads.map do |h|
117 repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) } 127 repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) }
app/views/repositories/_head.html.haml
1 .merge-tabs.repository 1 .merge-tabs.repository
2 = link_to project_repository_path(@project), :class => "activities-tab tab #{'active' if current_page?(project_repository_path(@project)) }" do 2 = link_to project_repository_path(@project), :class => "activities-tab tab #{'active' if current_page?(project_repository_path(@project)) }" do
3 %span 3 %span
4 - Activities 4 + History
5 = link_to branches_project_repository_path(@project), :class => "tab #{'active' if current_page?(branches_project_repository_path(@project)) }" do 5 = link_to branches_project_repository_path(@project), :class => "tab #{'active' if current_page?(branches_project_repository_path(@project)) }" do
6 %span 6 %span
7 Branches 7 Branches
app/views/repositories/branches.html.haml
@@ -6,5 +6,8 @@ @@ -6,5 +6,8 @@
6 %a.update-item{:href => project_commits_path(@project, :ref => branch.name)} 6 %a.update-item{:href => project_commits_path(@project, :ref => branch.name)}
7 %span.update-title{:style => "margin-bottom:0px;"} 7 %span.update-title{:style => "margin-bottom:0px;"}
8 = branch.name 8 = branch.name
  9 + %span.update-author.right
  10 + = time_ago_in_words(branch.commit.committed_date)
  11 + ago
9 - else 12 - else
10 %h3 No brances 13 %h3 No brances
app/views/repositories/show.html.haml
@@ -4,4 +4,18 @@ @@ -4,4 +4,18 @@
4 #news-feed.news-feed 4 #news-feed.news-feed
5 .project-box.project-updates.ui-box.ui-box-small.ui-box-big 5 .project-box.project-updates.ui-box.ui-box-small.ui-box-big
6 - @activities.each do |update| 6 - @activities.each do |update|
7 - = render "projects/feed", :update => update, :project => @project 7 + %a.project-update.titled{:href => project_commits_path(@project, :ref => update.head.name)}
  8 + = image_tag gravatar_icon(update.author_email), :class => "left", :width => 40
  9 + %span.update-title
  10 + = dashboard_feed_title(update)
  11 + %span.update-author
  12 + %strong= update.author_name
  13 + authored
  14 + = time_ago_in_words(update.created_at)
  15 + ago
  16 + .right-block
  17 + %span.update-title
  18 + %span.commit.tag= update.head.name
  19 + %span.update-author
  20 + .right= truncate update.commit.id
  21 +
app/views/repositories/tags.html.haml
@@ -6,5 +6,8 @@ @@ -6,5 +6,8 @@
6 %a.update-item{:href => project_commits_path(@project, :ref => tag.name)} 6 %a.update-item{:href => project_commits_path(@project, :ref => tag.name)}
7 %span.update-title{:style => "margin-bottom:0px;"} 7 %span.update-title{:style => "margin-bottom:0px;"}
8 = tag.name 8 = tag.name
  9 + %span.update-author.right
  10 + = time_ago_in_words(tag.commit.committed_date)
  11 + ago
9 - else 12 - else
10 %h3 No tags 13 %h3 No tags