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