给课程活动慢加上缓存,并且加入了开关
This commit is contained in:
parent
23a1f84ae7
commit
f58b530484
|
@ -695,21 +695,28 @@ class CoursesController < ApplicationController
|
|||
# 显示老师和助教的活动
|
||||
# @authors = searchTeacherAndAssistant(@course)
|
||||
@authors = course_all_member(@course)
|
||||
Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require file }
|
||||
events = []
|
||||
@authors.each do |author|
|
||||
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
|
||||
:with_subprojects => false,
|
||||
:author => author.user)
|
||||
key = "course_events_#{@course.id}".to_sym
|
||||
if Rails.env.production? && Setting.course_cahce_enabled?
|
||||
events = Rails.cache.read(key) || []
|
||||
end
|
||||
if events.empty?
|
||||
@authors.each do |author|
|
||||
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
|
||||
:with_subprojects => false,
|
||||
:author => author.user)
|
||||
|
||||
@activity.scope_select {|t| has["show_#{t}"]}
|
||||
# modify by nwb
|
||||
# 添加私密性判断
|
||||
if User.current.member_of_course?(@course)|| User.current.admin?
|
||||
events += @activity.events(@days, @course.created_at)
|
||||
else
|
||||
events += @activity.events(@days, @course.created_at, :is_public => 1)
|
||||
@activity.scope_select {|t| has["show_#{t}"]}
|
||||
# modify by nwb
|
||||
# 添加私密性判断
|
||||
if User.current.member_of_course?(@course)|| User.current.admin?
|
||||
events += @activity.events(@days, @course.created_at)
|
||||
else
|
||||
events += @activity.events(@days, @course.created_at, :is_public => 1)
|
||||
end
|
||||
end
|
||||
|
||||
Rails.cache.write(key, events) if Rails.env.production? && Setting.course_cahce_enabled?
|
||||
end
|
||||
else
|
||||
# @author = @course.teacher
|
||||
|
|
|
@ -2330,4 +2330,11 @@ module ApplicationHelper
|
|||
def cur_user_works_for_homework homework
|
||||
homework.student_works.where("user_id = ?",User.current).first
|
||||
end
|
||||
|
||||
def file_preview_tag(file, html_options={})
|
||||
if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)}
|
||||
link_to '预览', download_named_attachment_path(file.id, file.filename, preview: true),html_options
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -5,4 +5,6 @@ class Activity < ActiveRecord::Base
|
|||
validates :act_id, presence: true
|
||||
validates :act_type, presence: true
|
||||
validates :user_id, presence: true
|
||||
|
||||
include Trustie::Cache::ClearCourseEvent
|
||||
end
|
||||
|
|
|
@ -19,4 +19,5 @@ class ForgeActivity < ActiveRecord::Base
|
|||
validates :project_id,presence: true
|
||||
validates :forge_act_id,presence: true
|
||||
validates :forge_act_type, presence: true
|
||||
|
||||
end
|
||||
|
|
|
@ -126,4 +126,4 @@
|
|||
});
|
||||
nh_new_notify_count_show();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
<% if file.is_public? || User.current.member_of_course?(course) %>
|
||||
<div class="re_con_box" id="container_files_<%= file.id %>">
|
||||
<div class="">
|
||||
<%= link_to truncate(file.filename,length: 35, omission: '...'), download_named_attachment_path(file.id, file.filename, preview: true),:title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
|
||||
<%= link_to truncate(file.filename,length: 35, omission: '...'),
|
||||
download_named_attachment_path(file.id, file.filename),
|
||||
:title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
|
||||
<% if User.current.logged? %>
|
||||
<% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && course_contains_attachment?(@course,file) %>
|
||||
<%= link_to("选入我的其他课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select c_lorange",:remote => true) if has_course?(User.current,file) %>
|
||||
|
@ -40,7 +42,7 @@
|
|||
<% else %>
|
||||
<%= link_to("选入我的课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select c_lorange",:remote => true) if has_course?(User.current,file) %>
|
||||
<% end %>
|
||||
<%= link_to_attachment file, text: '下载', class: 'f_l re_open' %>
|
||||
<%= file_preview_tag(file, class: 'f_l re_open') %>
|
||||
<% else %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
<% project_attachments.each do |file| %>
|
||||
<div class="re_con_box">
|
||||
<div class="">
|
||||
<%= link_to truncate(file.filename,length: 35, omission: '...'), download_named_attachment_path(file.id, file.filename, preview: true),:title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
|
||||
<%= link_to truncate(file.filename,length: 35, omission: '...'),
|
||||
download_named_attachment_path(file.id, file.filename),
|
||||
:title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
|
||||
<% if User.current.logged? %>
|
||||
<% if (manage_allowed || file.author_id == User.current.id) && project_contains_attachment?(project,file) %>
|
||||
<%= link_to(l(:label_slected_to_other_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %>
|
||||
|
@ -30,7 +32,7 @@
|
|||
<% else %>
|
||||
<%= link_to(l(:label_slected_to_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %>
|
||||
<% end %>
|
||||
<%= link_to_attachment file, text: '下载', class: 'f_l re_open' %>
|
||||
<%= file_preview_tag(file, class: 'f_l re_open') %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
|
|
|
@ -66,7 +66,8 @@ upload_avatar_max_size:
|
|||
### delayjob for send email.
|
||||
delayjob_enabled:
|
||||
default: 1
|
||||
|
||||
course_cahce_enabled:
|
||||
default: 1
|
||||
bcc_recipients:
|
||||
default: 1
|
||||
plain_text_mail:
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Trustie
|
||||
module Cache
|
||||
module ClearCourseEvent
|
||||
def self.included(base)
|
||||
base.class_eval{
|
||||
after_create :clear_course_events
|
||||
}
|
||||
end
|
||||
def clear_course_events
|
||||
Rails.cache.delete("course_events_#{self.act.course_id}".to_sym) if Rails.env.production? && Setting.course_cahce_enabled?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue