添加缺陷回复统计

项目版本库提交次数统计
This commit is contained in:
huang 2016-01-13 12:53:09 +08:00
parent 5519ef78e2
commit a0ceb9b11c
6 changed files with 60 additions and 5 deletions

View File

@ -48,14 +48,14 @@ class Journal < ActiveRecord::Base
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
"(#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
before_create :split_private_notes
before_create :split_private_notes, :add_journals_count
# fq
after_save :act_as_activity,:be_user_score, :act_as_forge_message, :act_as_at_message
# end
#after_destroy :down_user_score
#before_save :be_user_score
after_destroy :down_user_score
after_destroy :down_user_score, :decrease_issues_journal_count
scope :visible, lambda {|*args|
user = args.shift || User.current
@ -214,4 +214,20 @@ class Journal < ActiveRecord::Base
end
end
# 减少留言数量统计
def decrease_issues_journal_count
unless self.issue.project.nil?
project = self.issue.project
project.update_attribute(:journals_count, project.journals_count - 1)
end
end
# issue留言总数更新
def add_journals_count
unless self.issue.project.nil? && self.journalized_type == "Issue"
project = self.issue.project
project.update_attribute(:journals_count, project.journals_count + 1)
end
end
end

View File

@ -1,8 +1,10 @@
class StaticProjectIssues < ActiveRecord::Migration
def up
Project.all.each do |project|
issues_count = project.issues.count
project.update_attribute(:issues_count, issues_count)
unless project.issues.nil?
issues_count = project.issues.count
project.update_attribute(:issues_count, issues_count)
end
end
end

View File

@ -0,0 +1,5 @@
class AddJournalsCountToProject < ActiveRecord::Migration
def change
add_column :projects, :journals_count, :integer, :default => false
end
end

View File

@ -0,0 +1,12 @@
class StaticsIssueJournal < ActiveRecord::Migration
def up
Project.all.each do |project|
if !project.project_score.nil? && !project.project_score.issue_journal_num.nil?
project.update_attribute(:journals_count, project.project_score.issue_journal_num)
end
end
end
def down
end
end

View File

@ -0,0 +1,19 @@
class StaticsRepositoryCommits < ActiveRecord::Migration
def up
g = Gitlab.client
Project.all.each do |project|
unless project.gpid.nil?
begin
puts project.id
count = g.project(project.gpid).commit_count
rescue
logger.error("The project's rep is not exit!")
end
project.update_attribute(:commits_count, count)
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160111080914) do
ActiveRecord::Schema.define(:version => 20160113023137) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1416,6 +1416,7 @@ ActiveRecord::Schema.define(:version => 20160111080914) do
t.integer "boards_count", :default => 0
t.integer "news_count", :default => 0
t.integer "acts_count", :default => 0
t.integer "journals_count", :default => 0
end
add_index "projects", ["lft"], :name => "index_projects_on_lft"