个人动态权限部分性能优化

This commit is contained in:
guange 2015-04-10 16:27:26 +08:00
parent c489d2400b
commit f94184bc81
2 changed files with 69 additions and 10 deletions

View File

@ -448,16 +448,73 @@ class UsersController < ApplicationController
end
activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc')
#Issue
# act_ids = Activity.where(act_type: 'Issue', user_id: user_ids).select('act_id').map{|x| x.act_id}
# project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id}
# valid_p_ids = []
# Project.where(id: project_ids).each do |x|
# x.visible?(User.current)
# valid_p_ids << x.id
# end
permission = !User.current.admin?
if permission
#Issue
act_ids = activity.where(act_type: 'Issue').select('act_id').map{|x| x.act_id}
project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id}
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
ids = []
ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id}
# activity = Activity.where(act_id: Issue.where(id: act_ids, project_id: valid_p_ids).map{|x| x.id}).order('id desc')
#Bid
act_ids = activity.where(act_type: 'Bid').select('act_id').map{|x| x.act_id}
course_ids = HomeworkForCourse.where(bid_id: act_ids).select('distinct course_id').map{|x| x.course_id}
c_ids = []
Course.where(id: course_ids).each do |x|
c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
end
ids << HomeworkForCourse.where(bid_id: act_ids, course_id: c_ids).map{|x| x.id}
#Journal
act_ids = activity.where(act_type: 'Journal').select('act_id').map{|x| x.act_id}
project_ids = Journal.where(id:act_ids, journalized_type: 'Project').select('distinct journalized_id').map{|x| x.journalized_id}
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id}
#News
act_ids = activity.where(act_type: 'News').select('act_id').map{|x| x.act_id}
project_ids = News.where(id: act_ids).select('distinct project_id').map{|x| x.project_id}
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id}
project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id}
c_ids = []
Course.where(id: project_ids).each do |x|
c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
end
ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id}
#Message
act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id}
board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id}
project_ids = Board.where(id: board_ids).select('distinct project_id').map{|x| x.project_id}
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id}
project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id}
c_ids = []
Course.where(id: project_ids).each do |x|
c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
end
ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id}
logger.debug "filter ids #{ids}"
activity = activity.where('act_id not in (?)', ids.flatten ).order('id desc') unless ids.flatten.empty?
end
# activity = activity.reject { |e|
# e.act.nil? ||
@ -468,6 +525,8 @@ class UsersController < ApplicationController
# (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) ||
# (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course))))))
# }
#
@activity_count = activity.count
@activity_pages = Paginator.new @activity_count, pre_count, params['page']
@activity = activity.slice(@activity_pages.offset,@activity_pages.per_page)

View File

@ -1,5 +1,5 @@
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 3
Delayed::Worker.sleep_delay = 10
Delayed::Worker.max_attempts = 1
Delayed::Worker.max_run_time = 5.minutes
Delayed::Worker.read_ahead = 10