userscore 事务
This commit is contained in:
parent
47e6c3eedd
commit
d2b5560d5e
|
@ -5,8 +5,9 @@ end
|
|||
|
||||
namespace :user_score do
|
||||
desc "calculating user score"
|
||||
# Rails.env = 'production'
|
||||
task :calculate => :environment do
|
||||
puts "truncating table...#{Rails.env}"
|
||||
UserScore.destroy_all
|
||||
puts "loading..."
|
||||
# collaboration 协同得分
|
||||
users = {}
|
||||
|
@ -40,10 +41,13 @@ namespace :user_score do
|
|||
end
|
||||
puts ":reply_posting calculate Completed. collaboration users count: #{users.count}"
|
||||
|
||||
UserScore.transaction do
|
||||
users.each do |user_id, score|
|
||||
UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score)
|
||||
end
|
||||
end
|
||||
puts "=== UserScore#collaboration calculate Completed. collaboration users count: #{users.count}"
|
||||
puts ""
|
||||
|
||||
users.clear
|
||||
|
||||
|
@ -55,10 +59,13 @@ namespace :user_score do
|
|||
end
|
||||
puts ":followed_by calculate Completed. influence users count: #{users_influence.count}"
|
||||
|
||||
UserScore.transaction do
|
||||
users_influence.each do |user_id, score|
|
||||
UserScore.find_or_create_by_user_id(user_id).update_attribute(:influence, score)
|
||||
end
|
||||
end
|
||||
puts "=== UserScore#influence calculate Completed. influence users count: #{users_influence.count}"
|
||||
puts ""
|
||||
# skill 技术得分
|
||||
# 顶踩帖
|
||||
users_skill = {}
|
||||
|
@ -91,10 +98,13 @@ namespace :user_score do
|
|||
end
|
||||
end
|
||||
puts ":praised_by_user and :treaded_by_user calculate Completed. skill users count: #{users_skill.count}"
|
||||
UserScore.transaction do
|
||||
users_skill.each do |user_id, score|
|
||||
UserScore.find_or_create_by_user_id(user_id).update_attribute(:skill, score)
|
||||
end
|
||||
end
|
||||
puts "=== UserScore#skill calculate Completed. skill users count: #{users_skill.count}"
|
||||
puts ""
|
||||
|
||||
# active 项目贡献得分
|
||||
users_active = {}
|
||||
|
@ -139,10 +149,14 @@ namespace :user_score do
|
|||
end
|
||||
puts ":post_issue calculate Completed. active users count: #{users_active.count}"
|
||||
|
||||
|
||||
UserScore.transaction do
|
||||
users_active.each do |user_id, score|
|
||||
UserScore.find_or_create_by_user_id(user_id).update_attribute(:active, score)
|
||||
end
|
||||
end
|
||||
puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}"
|
||||
puts ""
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -156,6 +170,6 @@ file 'tmp/test.yml' do
|
|||
:agent => "agent"
|
||||
}
|
||||
File.open('tmp/test.yml', 'w') do |f|
|
||||
f.write YAML.dump({'conf' => var })
|
||||
f.write YAML.dump({'conf' => var})
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue