Merge branch 'dev_cache' into 'dev_cache'
Redis 缓存课程动态优化 See merge request !58
This commit is contained in:
commit
5397707990
|
@ -331,17 +331,18 @@ class CourseCache
|
|||
key = 'course_acts:'+course_id.to_s
|
||||
data = Rails.cache.read(key)
|
||||
if data.nil?
|
||||
data = []
|
||||
# data = []
|
||||
course = Course.find(course_id)
|
||||
course.course_activities.each do |act|
|
||||
data << {
|
||||
:id=>act.id,
|
||||
:user_id=>act.user_id,
|
||||
:course_act_id=>act.course_act_id,
|
||||
:course_act_type=>act.course_act_type,
|
||||
:updated_at=>act.updated_at
|
||||
}
|
||||
end
|
||||
data = course.course_activities
|
||||
# course.course_activities.each do |act|
|
||||
# data << {
|
||||
# :id=>act.id,
|
||||
# :user_id=>act.user_id,
|
||||
# :course_act_id=>act.course_act_id,
|
||||
# :course_act_type=>act.course_act_type,
|
||||
# :updated_at=>act.updated_at
|
||||
# }
|
||||
# end
|
||||
|
||||
Rails.cache.write(key,data)
|
||||
end
|
||||
|
|
|
@ -1159,52 +1159,22 @@ class CoursesController < ApplicationController
|
|||
if params[:type].present?
|
||||
case params[:type]
|
||||
when "homework"
|
||||
course_activities = course_activities.select{|act|
|
||||
if act[:course_act_type] == 'HomeworkCommon'
|
||||
act
|
||||
end
|
||||
}
|
||||
@course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").includes(:course_act).order('updated_at desc')
|
||||
when "news"
|
||||
#@course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc')
|
||||
course_activities = course_activities.select{|act|
|
||||
if act[:course_act_type] == 'News'
|
||||
act
|
||||
end
|
||||
}
|
||||
@course_activities = course_activities.where("course_act_type = 'News'").includes(:course_act).order('updated_at desc')
|
||||
when "message"
|
||||
#@course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc')
|
||||
course_activities = course_activities.select{|act|
|
||||
if act[:course_act_type] == 'Message'
|
||||
act
|
||||
end
|
||||
}
|
||||
@course_activities = course_activities.sort { |a,b| b[:updated_at].to_i <=> a[:updated_at].to_i}
|
||||
@course_activities = course_activities.where("course_act_type = 'Message'").includes(:course_act).order('updated_at desc')
|
||||
when "poll"
|
||||
#@course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc')
|
||||
course_activities = course_activities.select{|act|
|
||||
if act[:course_act_type] == 'Poll'
|
||||
act
|
||||
end
|
||||
}
|
||||
@course_activities = course_activities.where("course_act_type = 'Poll'").includes(:course_act).order('updated_at desc')
|
||||
when "attachment"
|
||||
#@course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc')
|
||||
course_activities = course_activities.select{|act|
|
||||
if act[:course_act_type] == 'Attachment'
|
||||
act
|
||||
end
|
||||
}
|
||||
@course_activities = course_activities.where("course_act_type = 'Attachment'").includes(:course_act).order('updated_at desc')
|
||||
when "journalsForMessage"
|
||||
#@course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc')
|
||||
course_activities = course_activities.select{|act|
|
||||
if act[:course_act_type] == 'JournalsForMessage'
|
||||
act
|
||||
end
|
||||
}
|
||||
@course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").includes(:course_act).order('updated_at desc')
|
||||
else
|
||||
@course_activities = course_activities.includes(:course_act).order('updated_at desc')
|
||||
end
|
||||
@course_activities = course_activities.sort { |a,b| b[:updated_at].to_i <=> a[:updated_at].to_i}
|
||||
else
|
||||
@course_activities = course_activities.sort { |a,b| b[:updated_at].to_i <=> a[:updated_at].to_i}
|
||||
@course_activities = course_activities.includes(:course_act).order('updated_at desc')
|
||||
end
|
||||
@course_activities_count = @course_activities.count
|
||||
@course_activities = @course_activities[@page*10..(@page+1)*10-1]
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
</script>
|
||||
<style type="text/css">
|
||||
</style>
|
||||
<% course_activities.includes(:course_act).each do |activity| if course_activities %>
|
||||
<% course_activities.each do |activity| if course_activities %>
|
||||
<script>
|
||||
$(function () {
|
||||
sd_create_editor_from_data(<%= activity.id%>, null, "100%", "<%= activity.class.to_s %>");
|
||||
|
|
Loading…
Reference in New Issue