| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
b6b675d07c | 对course base做了缓存 | 10 years ago |
| @@ -53,7 +53,7 @@ gem 'elasticsearch-rails' | |||||
| gem "test-unit", "~>3.0" | gem "test-unit", "~>3.0" | ||||
| ### profile | ### profile | ||||
| gem 'oneapm_rpm' | |||||
| # gem 'oneapm_rpm' | |||||
| group :development do | group :development do | ||||
| gem 'grape-swagger' | gem 'grape-swagger' | ||||
| @@ -0,0 +1,53 @@ | |||||
| class CourseBaseCache | |||||
| class << self | |||||
| ## [ 1: { | |||||
| # teacher_num: 1, | |||||
| # student_num: 2, | |||||
| # course_file_num: 10 | |||||
| # }, ] | |||||
| include CoursesHelper | |||||
| def cache_with_course(course_id) | |||||
| data = cache[course_id] | |||||
| unless data | |||||
| course = Course.find(course_id) | |||||
| teacher_num = TeacherAndAssistantCount(course) | |||||
| student_num = studentCount(course) | |||||
| course_file_num = visable_attachemnts_incourse(course).count | |||||
| @cache_data[course_id] = { | |||||
| teacher_num: teacher_num, | |||||
| student_num: student_num, | |||||
| course_file_num: course_file_num | |||||
| } | |||||
| sync | |||||
| end | |||||
| @cache_data[course_id] | |||||
| end | |||||
| def update(course_id, opt={}) | |||||
| @cache_data[course_id] = cache_with_course(course_id).merge(opt) | |||||
| sync | |||||
| end | |||||
| private | |||||
| def sync | |||||
| Rails.cache.write("_course_base_num", @cache_data) | |||||
| end | |||||
| def cache | |||||
| @cache_data ||= Rails.cache.read("_course_base_num") || {} | |||||
| end | |||||
| end | |||||
| end | |||||
| @@ -3345,17 +3345,7 @@ end | |||||
| #获取所有子节点 | #获取所有子节点 | ||||
| def get_all_children result, jour | def get_all_children result, jour | ||||
| if jour.kind_of? Message | |||||
| jour.children.includes(:author, :praise_tread_cache).each do |jour_child| | |||||
| result << jour_child | |||||
| get_all_children_ex result, jour_child | |||||
| end | |||||
| elsif (jour.kind_of? JournalsForMessage) || (jour.kind_of? BlogComment) || (jour.kind_of? OrgDocumentComment) | |||||
| jour.children.each do |jour_child| | |||||
| result << jour_child | |||||
| get_all_children_ex result, jour_child | |||||
| end | |||||
| end | |||||
| get_all_children_ex result, jour | |||||
| if jour.respond_to?(:created_on) | if jour.respond_to?(:created_on) | ||||
| result.sort! { |a,b| b.created_on <=> a.created_on } | result.sort! { |a,b| b.created_on <=> a.created_on } | ||||
| elsif jour.respond_to?(:created_at) | elsif jour.respond_to?(:created_at) | ||||
| @@ -1,7 +1,13 @@ | |||||
| <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> | <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> | ||||
| <% teacher_num = TeacherAndAssistantCount(@course) %> | |||||
| <% student_num = studentCount(@course) %> | |||||
| <% course_file_num = visable_attachemnts_incourse(@course).count %> | |||||
| <%# teacher_num = TeacherAndAssistantCount(@course) %> | |||||
| <%# student_num = studentCount(@course) %> | |||||
| <%# course_file_num = visable_attachemnts_incourse(@course).count %> | |||||
| <% teacher_num = CourseBaseCache.cache_with_course(@course.id)[:teacher_num] %> | |||||
| <% student_num = CourseBaseCache.cache_with_course(@course.id)[:student_num] %> | |||||
| <% course_file_num = CourseBaseCache.cache_with_course(@course.id)[:course_file_num] %> | |||||
| <p class="sy_cgrey mb10 mr20"> | <p class="sy_cgrey mb10 mr20"> | ||||
| <%= link_to(@course.teacher.show_name, user_path(@course.teacher), :class => 'sy_cgrey') %> | <%= link_to(@course.teacher.show_name, user_path(@course.teacher), :class => 'sy_cgrey') %> | ||||
| > | > | ||||
| @@ -175,4 +175,4 @@ | |||||
| </li> | </li> | ||||
| </ul> | </ul> | ||||
| </div> | </div> | ||||
| <% end%> | |||||
| <% end%> | |||||
| @@ -12,7 +12,8 @@ RedmineApp::Application.configure do | |||||
| # Show full error reports and disable caching | # Show full error reports and disable caching | ||||
| config.consider_all_requests_local = true | config.consider_all_requests_local = true | ||||
| config.action_controller.perform_caching = true | config.action_controller.perform_caching = true | ||||
| config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" | |||||
| # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" | |||||
| config.cache_store = :redis_store, "redis://localhost:6379/0" | |||||
| #config.cache_store = :dalli_store | #config.cache_store = :dalli_store | ||||
| # Don't care if the mailer can't send | # Don't care if the mailer can't send | ||||
| config.action_mailer.raise_delivery_errors = true | config.action_mailer.raise_delivery_errors = true | ||||