| @@ -39,3 +39,5 @@ public/javascripts/wechat/node_modules/ | |||
| .access_token | |||
| tmux*.log | |||
| config/wechat.yml | |||
| config/environments/production.rb | |||
| config/oneapm.yml | |||
| @@ -27,7 +27,7 @@ module Mobile | |||
| ptc = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first | |||
| ptc.praise_minus(1) if !ptc.blank? | |||
| if ptc.praise_num == 0 | |||
| ptc.delete | |||
| ptc.destroy | |||
| end | |||
| obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first | |||
| num = !obj.blank? ? get_activity_praise_num(obj) : 0 | |||
| @@ -0,0 +1,100 @@ | |||
| #资源缓存 | |||
| class AttachmentsCache | |||
| class << self | |||
| #------------班级资源缓存--------------------- | |||
| def course_attachments_cache(course_id) | |||
| key = 'course_attachments:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| course = Course.find(course_id) | |||
| course.attachments.each do |attachment| | |||
| data << { | |||
| :id=>attachment.id, | |||
| :filesize=>attachment.filesize, | |||
| :downloads=>attachment.downloads, | |||
| :author_id=>attachment.author_id, | |||
| :created_on=>attachment.created_on, | |||
| :is_public=>attachment.is_public, | |||
| :is_publish=>attachment.is_publish, | |||
| :container_id=>attachment.container_id, | |||
| :container_type=>attachment.container_type, | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| #增加删除type | |||
| def update_course_attachments_cache(course_id,attachemnt_id,type,opt={}) | |||
| key = 'course_attachments:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # course = Course.find(course_id) | |||
| # course.attachments.each do |attachment| | |||
| # data << { | |||
| # :id=>attachment.id, | |||
| # :filesize=>attachment.filesize, | |||
| # :downloads=>attachment.downloads, | |||
| # :author_id=>attachment.author_id, | |||
| # :created_on=>attachment.created_on, | |||
| # :is_public=>attachment.is_public, | |||
| # :is_publish=>attachment.is_publish, | |||
| # :container_id=>attachment.container_id, | |||
| # :container_type=>attachment.container_type, | |||
| # } | |||
| # end | |||
| # | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 0 | |||
| #增加 | |||
| attachment = Attachment.find(attachemnt_id) | |||
| data << { | |||
| :id=>attachment.id, | |||
| :filesize=>attachment.filesize, | |||
| :downloads=>attachment.downloads, | |||
| :author_id=>attachment.author_id, | |||
| :created_on=>attachment.created_on, | |||
| :is_public=>attachment.is_public, | |||
| :is_publish=>attachment.is_publish, | |||
| :container_id=>attachment.container_id, | |||
| :container_type=>attachment.container_type, | |||
| } | |||
| elsif type == 1 | |||
| #删除 | |||
| data.each do |atta| | |||
| if atta[:id] == attachemnt_id | |||
| data.delete(atta) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #修改 | |||
| attachment = Attachment.find(attachemnt_id) | |||
| data.each_with_index do |atta,index| | |||
| if atta[:id] == attachemnt_id | |||
| data[index] = { | |||
| :id=>attachment.id, | |||
| :filesize=>attachment.filesize, | |||
| :downloads=>attachment.downloads, | |||
| :author_id=>attachment.author_id, | |||
| :created_on=>attachment.created_on, | |||
| :is_public=>attachment.is_public, | |||
| :is_publish=>attachment.is_publish, | |||
| :container_id=>attachment.container_id, | |||
| :container_type=>attachment.container_type, | |||
| } | |||
| break | |||
| end | |||
| end | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| class CommentCache | |||
| class<<self | |||
| #-----------------------------新闻回复 | |||
| def comment_cache(id) | |||
| key = "comment:"+id.to_s | |||
| data = Rails.cache.read(key) rescue nil | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = Comment.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_comment_cache(id,comment) | |||
| key = "comment:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| else | |||
| Rails.cache.write(key,comment,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| #删除 | |||
| def delete_comment_cache(id) | |||
| key = "comment:"+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,534 @@ | |||
| #班级相关的缓存 | |||
| class CourseCache | |||
| class << self | |||
| include CoursesHelper | |||
| #-----------------------------数据统计 课程老师、学生数、动态数、通知数 | |||
| def course_count_cache(course_id) | |||
| key = "course_count:"+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| course = Course.find(course_id) | |||
| teacher_num = TeacherAndAssistantCount(course) | |||
| student_num = studentCount(course) | |||
| act_count = course.course_activities.count | |||
| news_count = course.news.count | |||
| data = { | |||
| :teacher_num=>teacher_num, | |||
| :student_num=>student_num, | |||
| :act_count=>act_count, | |||
| :news_count=>news_count | |||
| } | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_course_count_cache(course_id,opt={}) | |||
| key = "course_count:"+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # course = Course.find(course_id) | |||
| # teacher_num = TeacherAndAssistantCount(course) | |||
| # student_num = studentCount(course) | |||
| # act_count = course.course_activities.count | |||
| # news_count = course.news.count | |||
| # | |||
| # data = { | |||
| # :teacher_num=>teacher_num, | |||
| # :student_num=>student_num, | |||
| # :act_count=>act_count, | |||
| # :news_count=>news_count | |||
| # } | |||
| # | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| data = data.merge(opt) | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #----------------------作业列表------------------------------ | |||
| def course_homeworks_cache(course_id) | |||
| key = 'course_homeworks:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| course = Course.find(course_id) | |||
| course.homework_commons.order("created_at desc").each do |homework| | |||
| data << { | |||
| :id=>homework.id, | |||
| :name=>homework.name, | |||
| :user_id=>homework.user_id, | |||
| :publish_time=>homework.publish_time, | |||
| :updated_at=>homework.created_at, | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| #增加删除 type | |||
| def update_course_homeworks_cache(course_id,homework_id,type,opt={}) | |||
| key = 'course_homeworks:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # course = Course.find(course_id) | |||
| # course.homework_commons.order("created_at desc").each do |homework| | |||
| # data << { | |||
| # :id=>homework.id, | |||
| # :name=>homework.name, | |||
| # :user_id=>homework.user_id, | |||
| # :publish_time=>homework.publish_time, | |||
| # :updated_at=>homework.created_at, | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 0 | |||
| #增加 | |||
| homework = HomeworkCommon.find(homework_id) | |||
| #增加在第一个 | |||
| opt = { | |||
| :id=>homework.id, | |||
| :name=>homework.name, | |||
| :user_id=>homework.user_id, | |||
| :publish_time=>homework.publish_time, | |||
| :updated_at=>homework.created_at, | |||
| } | |||
| data.insert(0,opt) | |||
| elsif type == 1 | |||
| #删除 | |||
| data.each do |homework| | |||
| if homework[:id] == homework_id | |||
| data.delete(homework) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #修改 | |||
| data.each_with_index do |homework,index| | |||
| if homework[:id] == homework_id | |||
| data[index] = data[index].merge(opt) | |||
| break | |||
| end | |||
| end | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #--------------------班级活跃度列表--------------------- | |||
| def course_contributor_score_cache(course_id) | |||
| key = 'course_contributor_score:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| # course = Course.find(course_id) | |||
| # course.course_contributor_scores.each do |contributor_score| | |||
| # data << { | |||
| # :id=>contributor_score.id, | |||
| # :user_id=>contributor_score.user_id, | |||
| # :resource_num=>contributor_score.resource_num, | |||
| # :message_num=>contributor_score.message_num, | |||
| # :message_reply_num=>contributor_score.message_reply_num, | |||
| # :journal_num=>contributor_score.journal_num, | |||
| # :homework_journal_num=>contributor_score.homework_journal_num, | |||
| # :news_reply_num=>contributor_score.news_reply_num, | |||
| # :news_num=>contributor_score.news_num, | |||
| # :total_score=>contributor_score.resource_num.to_i * 5 + contributor_score.message_num.to_i * 2 + | |||
| # contributor_score.message_reply_num.to_i * 1 + contributor_score.journal_num.to_i * 1 + | |||
| # + contributor_score.homework_journal_num.to_i * 1 + contributor_score.news_reply_num.to_i * 1 + | |||
| # contributor_score.news_num.to_i * 1 | |||
| # } | |||
| # end | |||
| ccs = CourseContributorScore.find_by_sql("SELECT ccs.*, (message_num*2 + message_reply_num + news_reply_num + news_num + | |||
| resource_num*5 + journal_num + homework_journal_num ) as con_score FROM `course_contributor_scores` ccs JOIN students_for_courses sfs | |||
| ON sfs.student_id = ccs.user_id AND sfs.course_id = ccs.course_id where ccs.course_id = #{course_id} order by | |||
| con_score desc;") | |||
| ccs.each do |contributor_score| | |||
| data << { | |||
| :id=>contributor_score.id, | |||
| :user_id=>contributor_score.user_id, | |||
| :resource_num=>contributor_score.resource_num, | |||
| :message_num=>contributor_score.message_num, | |||
| :message_reply_num=>contributor_score.message_reply_num, | |||
| :journal_num=>contributor_score.journal_num, | |||
| :homework_journal_num=>contributor_score.homework_journal_num, | |||
| :news_reply_num=>contributor_score.news_reply_num, | |||
| :news_num=>contributor_score.news_num, | |||
| :total_score=>contributor_score.con_score | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def update_course_contributor_score_cache(course_id,user_id,opt={}) | |||
| key = 'course_contributor_score:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # ccs = CourseContributorScore.find_by_sql("SELECT ccs.*, (message_num*2 + message_reply_num + news_reply_num + news_num + | |||
| # resource_num*5 + journal_num + homework_journal_num ) as con_score FROM `course_contributor_scores` ccs JOIN students_for_courses sfs | |||
| # ON sfs.student_id = ccs.user_id AND sfs.course_id = ccs.course_id where ccs.course_id = #{course_id} order by | |||
| # con_score desc;") | |||
| # | |||
| # ccs.each do |contributor_score| | |||
| # data << { | |||
| # :id=>contributor_score.id, | |||
| # :user_id=>contributor_score.user_id, | |||
| # :resource_num=>contributor_score.resource_num, | |||
| # :message_num=>contributor_score.message_num, | |||
| # :message_reply_num=>contributor_score.message_reply_num, | |||
| # :journal_num=>contributor_score.journal_num, | |||
| # :homework_journal_num=>contributor_score.homework_journal_num, | |||
| # :news_reply_num=>contributor_score.news_reply_num, | |||
| # :news_num=>contributor_score.news_num, | |||
| # :total_score=>contributor_score.con_score | |||
| # } | |||
| # end | |||
| # | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| has_record = false | |||
| data.each_with_index do |contributor_score,index| | |||
| if contributor_score[:user_id] == user_id | |||
| data[index] = data[index].merge(opt) | |||
| has_record = true | |||
| break | |||
| end | |||
| end | |||
| if !has_record | |||
| data << opt | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #--------------------班级英雄榜列表--------------------- | |||
| def course_heroes_cache(course_id) | |||
| key = 'course_heroes:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| course = Course.find(course_id) | |||
| sql_select = "SELECT members.*,( | |||
| SELECT SUM(work_score) | |||
| FROM student_works,homework_commons | |||
| WHERE student_works.homework_common_id = homework_commons.id | |||
| AND homework_commons.course_id = #{course_id} | |||
| AND student_works.user_id = members.user_id | |||
| ) AS score | |||
| FROM members | |||
| JOIN students_for_courses | |||
| ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id | |||
| WHERE members.course_id = #{course_id} " | |||
| homework_scores = Member.find_by_sql(sql_select) | |||
| homework_scores.each do |hero| | |||
| data << { | |||
| :score=>hero.score, | |||
| :user_id=>hero.user_id | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def update_course_heroes_cache(course_id,user_id,type,opt={}) | |||
| key = 'course_heroes:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # course = Course.find(course_id) | |||
| # sql_select = "SELECT members.*,( | |||
| # SELECT SUM(work_score) | |||
| # FROM student_works,homework_commons | |||
| # WHERE student_works.homework_common_id = homework_commons.id | |||
| # AND homework_commons.course_id = #{course_id} | |||
| # AND student_works.user_id = members.user_id | |||
| # ) AS score | |||
| # FROM members | |||
| # JOIN students_for_courses | |||
| # ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id | |||
| # WHERE members.course_id = #{course_id} ORDER BY score desc" | |||
| # homework_scores = Member.find_by_sql(sql_select) | |||
| # | |||
| # homework_scores.each do |hero| | |||
| # data << { | |||
| # :score=>hero.score, | |||
| # :user_id=>hero.user_id | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 0 | |||
| #不管存不存在都更新 | |||
| sql_select = "SELECT members.*,( | |||
| SELECT SUM(work_score) | |||
| FROM student_works,homework_commons | |||
| WHERE student_works.homework_common_id = homework_commons.id | |||
| AND homework_commons.course_id = #{course_id} | |||
| AND student_works.user_id = #{user_id} | |||
| ) AS score | |||
| FROM members | |||
| JOIN students_for_courses | |||
| ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id | |||
| WHERE members.course_id = #{course_id} and members.user_id = #{user_id}" | |||
| result = Member.find_by_sql(sql_select).first | |||
| if result | |||
| score = result.score | |||
| opt={ | |||
| :score=>score, | |||
| :user_id=>user_id | |||
| } | |||
| has_record = false | |||
| data.each_with_index do |hero,index| | |||
| if hero[:user_id] == user_id | |||
| data[index] = data[index].merge(opt) | |||
| has_record = true | |||
| break | |||
| end | |||
| end | |||
| if !has_record | |||
| data << opt | |||
| end | |||
| end | |||
| else | |||
| has_record = false | |||
| data.each_with_index do |hero,index| | |||
| if hero[:user_id] == user_id | |||
| data[index] = data[index].merge(opt) | |||
| has_record = true | |||
| break | |||
| end | |||
| end | |||
| if !has_record | |||
| data << opt | |||
| end | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #--------------------班级动态列表--------------------- | |||
| def course_acts_cache(course_id) | |||
| key = 'course_acts:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| 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 | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| #更新内容 | |||
| def update_course_acts_cache(course_id,course_act_id,course_act_type,opt={}) | |||
| key = 'course_acts:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # 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 | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| data.each_with_index do |act,index| | |||
| if act[:course_act_id] == course_act_id && act[:course_act_type] == course_act_type | |||
| data[index] = data[index].merge(opt) | |||
| break | |||
| end | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #更新条数 | |||
| def update_course_acts_nums_cache(course_id,course_act,type) | |||
| key = 'course_acts:'+course_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # 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 | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 1 | |||
| #删除 | |||
| data.each do |act| | |||
| if act[:id] == course_act.id | |||
| data.delete(act) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #增加 | |||
| data << { | |||
| :id=>course_act.id, | |||
| :user_id=>course_act.user_id, | |||
| :course_act_id=>course_act.course_act_id, | |||
| :course_act_type=>course_act.course_act_type, | |||
| :updated_at=>course_act.updated_at | |||
| } | |||
| update_excelletn_courses_cache(course_id,3,{:updated_at=>course_act.updated_at}) | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| course_count = course_count_cache(course_id) | |||
| if type == 1 | |||
| update_course_count_cache(course_id,{:act_count=>course_count[:act_count]-1}) | |||
| else | |||
| update_course_count_cache(course_id,{:act_count=>course_count[:act_count]+1}) | |||
| end | |||
| end | |||
| #--------------------精品课程--------------------- | |||
| def excelletn_courses_cache() | |||
| key = 'excelletn_courses' | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| sql = "SELECT c.id,max(cs.updated_at) updated_at FROM course_activities cs, courses c where cs.course_id = c.id | |||
| and (c.is_excellent =1 or c.excellent_option =1) and c.is_public = 1 group by id order by updated_at desc ;" | |||
| Course.find_by_sql(sql).each do |ec| | |||
| data << { | |||
| :id=>ec.id, | |||
| :tags=>ec.tags, | |||
| :updated_at=>ec.updated_at | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| #更新内容 | |||
| def update_excelletn_courses_cache(course_id,type,opt={}) | |||
| key = 'excelletn_courses' | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # | |||
| # sql = "SELECT c.id,max(cs.updated_at) updated_at FROM course_activities cs, courses c where cs.course_id = c.id | |||
| # and (c.is_excellent =1 or c.excellent_option =1) and c.is_public = 1 group by id order by updated_at desc ;" | |||
| # | |||
| # Course.find_by_sql(sql).each do |ec| | |||
| # data << { | |||
| # :id=>ec.id, | |||
| # :tags=>ec.tags, | |||
| # :updated_at=>ec.updated_at | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 1 | |||
| #增加 | |||
| course = Course.find(course_id) | |||
| if course.is_public == 1 | |||
| sql = "SELECT max(updated_at) updated_at FROM course_activities where course_id =#{course_id}" | |||
| info = Course.find_by_sql(sql).first | |||
| data << { | |||
| :id=>course_id, | |||
| :tags=>course.tags, | |||
| :updated_at=>info.updated_at | |||
| } | |||
| end | |||
| elsif type == 2 | |||
| #删除 | |||
| data.each do |ec| | |||
| if ec[:id] == course_id | |||
| data.delete(ec) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #修改 | |||
| data.each_with_index do |ex,index| | |||
| if ex[:id] == course_id | |||
| data[index] = data[index].merge(opt) | |||
| break | |||
| end | |||
| end | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #-----------------------------班级最新动态时间-------------- | |||
| def course_act_updated_at_cache(course_id) | |||
| key = "course_act_updated_at" | |||
| data = Rails.cache.read(key) || [] | |||
| if data[course_id].nil? | |||
| sql = "SELECT max(updated_at) updated_at FROM course_activities where course_id =#{course_id}" | |||
| updated_at = Course.find_by_sql(sql).first.updated_at | |||
| data[course_id] = updated_at | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data[course_id] | |||
| end | |||
| #更新 | |||
| def update_course_act_updated_at_cache(course_id) | |||
| key = "course_act_updated_at" | |||
| data = Rails.cache.read(key) || [] | |||
| sql = "SELECT max(updated_at) updated_at FROM course_activities where course_id =#{course_id}" | |||
| updated_at = Course.find_by_sql(sql).first.updated_at | |||
| data[course_id] = updated_at | |||
| Rails.cache.write(key,data) | |||
| end | |||
| #更新 | |||
| def update_course_act_updated_at_to_0_cache(course_id) | |||
| key = "course_act_updated_at" | |||
| data = Rails.cache.read(key) || [] | |||
| data[course_id] = 0 | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| class HomeworkCommonCache | |||
| class<<self | |||
| #-----------------------------作业 | |||
| def homework_common_cache(id) | |||
| key = "homework_common:"+id.to_s | |||
| data = Rails.cache.read(key) rescue nil | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = HomeworkCommon.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_homework_common_cache(id,homework_common) | |||
| key = "homework_common:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| else | |||
| Rails.cache.write(key,homework_common,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| #删除 | |||
| def delete_homework_common_cache(id) | |||
| key = "homework_common:"+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| class IssueCache | |||
| class<<self | |||
| #-----------------------------讨论区帖子 | |||
| def issue_cache(id) | |||
| key = "issue:"+id.to_s | |||
| data = Rails.cache.read(key) rescue nil | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = Issue.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_issue_cache(id,issue) | |||
| key = "issue:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| else | |||
| Rails.cache.write(key,issue,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| #删除 | |||
| def delete_issue_cache(id) | |||
| key = "issue:"+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| class JournalsForMessageCache | |||
| class<<self | |||
| #-----------------------------新闻回复 | |||
| def journalsformessage_cache(id) | |||
| key = "journalsformessage:"+id.to_s | |||
| data = Rails.cache.read(key) rescue nil | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = JournalsForMessage.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_journalsformessage_cache(id,journalsformessage) | |||
| key = "journalsformessage:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| else | |||
| Rails.cache.write(key,journalsformessage,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| #删除 | |||
| def delete_journalsformessage_cache(id) | |||
| key = "journalsformessage:"+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| class MessagesCache | |||
| class<<self | |||
| #-----------------------------讨论区帖子 | |||
| def message_cache(id) | |||
| key = "message:"+id.to_s | |||
| data = Rails.cache.read(key) rescue nil | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = Message.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_message_cache(id,message) | |||
| key = "message:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| else | |||
| Rails.cache.write(key,message,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| #删除 | |||
| def delete_message_cache(id) | |||
| key = "message:"+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| class NewsCache | |||
| class<<self | |||
| #-----------------------------讨论区帖子 | |||
| def news_cache(id) | |||
| key = "news:"+id.to_s | |||
| data = Rails.cache.read(key) rescue nil | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = News.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_news_cache(id,news) | |||
| key = "news:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| else | |||
| Rails.cache.write(key,news,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key) | |||
| end | |||
| end | |||
| #删除 | |||
| def delete_news_cache(id) | |||
| key = "news:"+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,65 @@ | |||
| #资源缓存 | |||
| class PraiseCache | |||
| class << self | |||
| #------------帖子赞数缓存--------------------- | |||
| def praise_cache(object_id,object_type) | |||
| object_type = object_type.to_s | |||
| key = 'praise:'+object_type+":"+object_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = {} | |||
| praise = PraiseTreadCache.where("object_id=#{object_id} and object_type='#{object_type}'").first | |||
| praise_num = praise.nil? ? 0 : praise.praise_num | |||
| data = { | |||
| :object_id=>object_id, | |||
| :object_type=>object_type, | |||
| :praise_num=>praise_num | |||
| } | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def update_praise_cache(object_id,object_type,opt={}) | |||
| object_type = object_type.to_s | |||
| key = 'praise:'+object_type+":"+object_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = {} | |||
| # praise = PraiseTreadCache.where("object_id=#{object_id} and object_type='#{object_type}'") | |||
| # praise_num = praise.nil? ? 0 : praise.praise_num | |||
| # data = { | |||
| # :object_id=>object_id, | |||
| # :object_type=>object_type, | |||
| # :praise_num=>praise_num | |||
| # } | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| data = data.merge(opt) | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #------------帖子已赞、未赞缓存--------------------- | |||
| def ispraise_cache(user_id,object_id,object_type) | |||
| object_type = object_type.to_s | |||
| key = 'ispraise:'+object_type+":"+object_id.to_s+":"+user_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = false | |||
| unless PraiseTread.where(praise_tread_object_id: object_id,praise_tread_object_type: object_type,user_id: user_id).empty? | |||
| data = true | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def update_ispraise_cache(user_id,object_id,object_type,flag) | |||
| object_type = object_type.to_s | |||
| key = 'ispraise:'+object_type+":"+object_id.to_s+":"+user_id.to_s | |||
| Rails.cache.write(key,flag) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,138 @@ | |||
| class ProjectCache | |||
| class<<self | |||
| #-----------------------------数据统计-------------- | |||
| #--------------------项目动态列表--------------------- | |||
| def project_acts_cache(project_id) | |||
| key = 'project_acts:'+project_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| forge_acts = ForgeActivity.where("project_id = ?", project_id) | |||
| forge_acts.each do |act| | |||
| data << { | |||
| :id=>act.id, | |||
| :user_id=>act.user_id, | |||
| :forge_act_id=>act.forge_act_id, | |||
| :forge_act_type=>act.forge_act_type, | |||
| :updated_at=>act.updated_at.to_i, | |||
| :created_at=>act.created_at.to_i | |||
| } | |||
| end | |||
| data = data.to_json | |||
| Rails.cache.write(key,data) | |||
| end | |||
| JSON.parse(data) | |||
| end | |||
| #更新内容 | |||
| def update_project_acts_cache(project_id,forge_act_id,forge_act_type,opt={}) | |||
| key = 'project_acts:'+project_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # forge_acts = ForgeActivity.where("project_id = ?", project_id) | |||
| # forge_acts.each do |act| | |||
| # data << { | |||
| # :id=>act.id, | |||
| # :user_id=>act.user_id, | |||
| # :forge_act_id=>act.forge_act_id, | |||
| # :forge_act_type=>act.forge_act_type, | |||
| # :updated_at=>act.updated_at.to_i, | |||
| # :created_at=>act.created_at.to_i | |||
| # } | |||
| # end | |||
| # data = data.to_json | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| data = JSON.parse(data) | |||
| data.each_with_index do |act,index| | |||
| if act['forge_act_id'] == forge_act_id && act['forge_act_type'] == forge_act_type | |||
| data[index] = data[index].merge(opt) | |||
| break | |||
| end | |||
| end | |||
| data = data.to_json | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #更新条数 | |||
| def update_project_acts_nums_cache(project_id,project_act,type) | |||
| key = 'project_acts:'+project_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| forge_acts = ForgeActivity.where("project_id = ?", project_id) | |||
| forge_acts.each do |act| | |||
| data << { | |||
| :id=>act.id, | |||
| :user_id=>act.user_id, | |||
| :forge_act_id=>act.forge_act_id, | |||
| :forge_act_type=>act.forge_act_type, | |||
| :updated_at=>act.updated_at.to_i, | |||
| :created_at=>act.created_at.to_i | |||
| } | |||
| end | |||
| data = data.to_json | |||
| Rails.cache.write(key,data) | |||
| else | |||
| data = JSON.parse(data) | |||
| if type == 1 | |||
| #删除 | |||
| data.each do |act| | |||
| if act['id'] == project_act.id | |||
| data.delete(act) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #增加 | |||
| data << { | |||
| :id=>project_act.id, | |||
| :user_id=>project_act.user_id, | |||
| :forge_act_id=>project_act.forge_act_id, | |||
| :forge_act_type=>project_act.forge_act_type, | |||
| :updated_at=>project_act.updated_at.to_i, | |||
| :created_at=>project_act.created_at.to_i | |||
| } | |||
| end | |||
| data = data.to_json | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #-----------------------------项目最新动态时间-------------- | |||
| def project_act_updated_at_cache(project_id) | |||
| key = "project_act_updated_at" | |||
| data = Rails.cache.read(key) || [] | |||
| if data[project_id].nil? | |||
| sql = "SELECT max(updated_at) updated_at FROM forge_activities where project_id =#{project_id}" | |||
| updated_at = Project.find_by_sql(sql).first.updated_at | |||
| data[project_id] = updated_at | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data[project_id] | |||
| end | |||
| #更新 | |||
| def update_project_act_updated_at_cache(project_id) | |||
| key = "project_act_updated_at" | |||
| data = Rails.cache.read(key) || [] | |||
| sql = "SELECT max(updated_at) updated_at FROM forge_activities where project_id =#{project_id}" | |||
| updated_at = Project.find_by_sql(sql).first.updated_at | |||
| data[project_id] = updated_at | |||
| Rails.cache.write(key,data) | |||
| end | |||
| #更新 | |||
| def update_project_act_updated_at_to_0_cache(project_id) | |||
| key = "project_act_updated_at" | |||
| data = Rails.cache.read(key) || [] | |||
| data[project_id] = 0 | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,469 @@ | |||
| class ReplyCache | |||
| class<<self | |||
| #------------讨论区帖子的回复--------------------- | |||
| def message_replys_cache(id) | |||
| key = 'message_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| replys = Message.where("root_id = #{id}").reorder("created_on desc") | |||
| replys.each do |reply| | |||
| data << { | |||
| :id=>reply.id, | |||
| :parent_id=>reply.parent_id, | |||
| :created_on=>reply.created_on | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def get_message_reply_parents_cache(id,reply_id) | |||
| replys = message_replys_cache(id) | |||
| results = [] | |||
| #本身已排好序只需一级级往下找就是,先找到初始点 | |||
| parent_id = 0 | |||
| replys.each do |reply| | |||
| if reply[:id] == reply_id | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| elsif parent_id != 0 | |||
| if reply[:id] == parent_id | |||
| results << reply | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| end | |||
| end | |||
| end | |||
| results | |||
| end | |||
| #更新就是 删除/增加回复/数据库更新之后再调用!!!!!!!!! /新增的插到第一条!!!!.insert(0,m) .delete(m) | |||
| def update_message_replys_cache(id,message_reply,type) | |||
| key = 'message_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # replys = Message.where("root_id = #{id}").reorder("created_on desc") | |||
| # | |||
| # replys.each do |reply| | |||
| # data << { | |||
| # :id=>reply.id, | |||
| # :parent_id=>reply.parent_id, | |||
| # :created_on=>reply.created_on | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 1 | |||
| #删除 | |||
| data.each do |reply| | |||
| if reply[:id] == message_reply.id | |||
| data.delete(reply) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #增加 | |||
| opt = { | |||
| :id=>message_reply.id, | |||
| :parent_id=>message_reply.parent_id, | |||
| :created_on=>message_reply.created_on | |||
| } | |||
| data.insert(0,opt) | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| def delete_message_replys_cache(id) | |||
| key = 'message_reply:'+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| #------------通知新闻帖子的回复--------------------- | |||
| def news_replys_cache(id) | |||
| key = 'news_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| news = News.find(id) | |||
| replys = news.comments.reorder("created_on desc") | |||
| replys.each do |reply| | |||
| data << { | |||
| :id=>reply.id, | |||
| :parent_id=>reply.parent_id, | |||
| :created_on=>reply.created_on | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def get_news_reply_parents_cache(id,reply_id) | |||
| replys = news_replys_cache(id) | |||
| results = [] | |||
| #本身已排好序只需一级级往下找就是,先找到初始点 | |||
| parent_id = 0 | |||
| replys.each do |reply| | |||
| if reply[:id] == reply_id | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| elsif parent_id != 0 | |||
| if reply[:id] == parent_id | |||
| results << reply | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| end | |||
| end | |||
| end | |||
| results | |||
| end | |||
| #更新就是 删除/增加回复/数据库更新之后再调用!!!!!!!!! /新增的插到第一条!!!!.insert(0,m) .delete(m) | |||
| def update_news_replys_cache(id,news_reply,type) | |||
| key = 'news_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # news = News.find(id) | |||
| # replys = news.comments.reorder("created_on desc") | |||
| # | |||
| # replys.each do |reply| | |||
| # data << { | |||
| # :id=>reply.id, | |||
| # :parent_id=>reply.parent_id, | |||
| # :created_on=>reply.created_on | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 1 | |||
| #删除 | |||
| data.each do |reply| | |||
| if reply[:id] == news_reply.id | |||
| data.delete(reply) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #增加 | |||
| opt = { | |||
| :id=>news_reply.id, | |||
| :parent_id=>news_reply.parent_id, | |||
| :created_on=>news_reply.created_on | |||
| } | |||
| data.insert(0,opt) | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| def delete_news_replys_cache(id) | |||
| key = 'news_reply:'+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| #------------作业帖子的回复--------------------- | |||
| def homework_replys_cache(id) | |||
| key = 'homework_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| homework = HomeworkCommon.find(id) | |||
| replys = homework.journals_for_messages.reorder("created_on desc") | |||
| replys.each do |reply| | |||
| data << { | |||
| :id=>reply.id, | |||
| :parent_id=>reply.m_parent_id, | |||
| :created_on=>reply.created_on | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def get_homework_reply_parents_cache(id,reply_id) | |||
| replys = homework_replys_cache(id) | |||
| results = [] | |||
| #本身已排好序只需一级级往下找就是,先找到初始点 | |||
| parent_id = 0 | |||
| replys.each do |reply| | |||
| if reply[:id] == reply_id | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| elsif parent_id != 0 | |||
| if reply[:id] == parent_id | |||
| results << reply | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| end | |||
| end | |||
| end | |||
| results | |||
| end | |||
| #更新就是 删除/增加回复/数据库更新之后再调用!!!!!!!!! /新增的插到第一条!!!!.insert(0,m) .delete(m) | |||
| def update_homework_replys_cache(id,homework_reply,type) | |||
| key = 'homework_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # homework = HomeworkCommon.find(id) | |||
| # replys = homework.journals_for_messages.reorder("created_on desc") | |||
| # | |||
| # replys.each do |reply| | |||
| # data << { | |||
| # :id=>reply.id, | |||
| # :parent_id=>reply.m_parent_id, | |||
| # :created_on=>reply.created_on | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 1 | |||
| #删除 | |||
| data.each do |reply| | |||
| if reply[:id] == homework_reply.id | |||
| data.delete(reply) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #增加 | |||
| opt = { | |||
| :id=>homework_reply.id, | |||
| :parent_id=>homework_reply.m_parent_id, | |||
| :created_on=>homework_reply.created_on | |||
| } | |||
| data.insert(0,opt) | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| def delete_homework_replys_cache(id) | |||
| key = 'homework_reply:'+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| #------------留言的回复--------------------- | |||
| def leave_replys_cache(id) | |||
| key = 'leave_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| replys = JournalsForMessage.where("root_id = #{id}").reorder("created_on desc") | |||
| replys.each do |reply| | |||
| data << { | |||
| :id=>reply.id, | |||
| :parent_id=>reply.m_parent_id, | |||
| :created_on=>reply.created_on | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def get_leave_reply_parents_cache(id,reply_id) | |||
| replys = leave_replys_cache(id) | |||
| results = [] | |||
| #本身已排好序只需一级级往下找就是,先找到初始点 | |||
| parent_id = 0 | |||
| replys.each do |reply| | |||
| if reply[:id] == reply_id | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| elsif parent_id != 0 | |||
| if reply[:id] == parent_id | |||
| results << reply | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| end | |||
| end | |||
| end | |||
| results | |||
| end | |||
| #更新就是 删除/增加回复/数据库更新之后再调用!!!!!!!!! /新增的插到第一条!!!!.insert(0,m) .delete(m) | |||
| def update_leave_replys_cache(id,leave_reply,type) | |||
| key = 'leave_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # replys = JournalsForMessage.where("root_id = #{id}").reorder("created_on desc") | |||
| # replys.each do |reply| | |||
| # data << { | |||
| # :id=>reply.id, | |||
| # :parent_id=>reply.m_parent_id, | |||
| # :created_on=>reply.created_on | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 1 | |||
| #删除 | |||
| data.each do |reply| | |||
| if reply[:id] == leave_reply.id | |||
| data.delete(reply) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #增加 | |||
| opt = { | |||
| :id=>leave_reply.id, | |||
| :parent_id=>leave_reply.m_parent_id, | |||
| :created_on=>leave_reply.created_on | |||
| } | |||
| data.insert(0,opt) | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| def delete_leave_replys_cache(id) | |||
| key = 'leave_reply:'+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| #------------博客的回复--------------------- | |||
| def blog_replys_cache(id) | |||
| key = 'blog_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| replys = BlogComment.where("root_id = #{id}").reorder("created_on desc") | |||
| replys.each do |reply| | |||
| data << { | |||
| :id=>reply.id, | |||
| :parent_id=>reply.parent_id, | |||
| :created_on=>reply.created_on | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| def get_blog_reply_parents_cache(id,reply_id) | |||
| replys = blog_replys_cache(id) | |||
| results = [] | |||
| #本身已排好序只需一级级往下找就是,先找到初始点 | |||
| parent_id = 0 | |||
| replys.each do |reply| | |||
| if reply[:id] == reply_id | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| elsif parent_id != 0 | |||
| if reply[:id] == parent_id | |||
| results << reply | |||
| if reply[:parent_id].nil? | |||
| break | |||
| else | |||
| parent_id = reply[:parent_id] | |||
| end | |||
| end | |||
| end | |||
| end | |||
| results | |||
| end | |||
| #更新就是 删除/增加回复/数据库更新之后再调用!!!!!!!!! /新增的插到第一条!!!!.insert(0,m) .delete(m) | |||
| def update_blog_replys_cache(id,blog_reply,type) | |||
| key = 'blog_reply:'+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # replys = BlogComment.where("root_id = #{id}").reorder("created_on desc") | |||
| # replys.each do |reply| | |||
| # data << { | |||
| # :id=>reply.id, | |||
| # :parent_id=>reply.parent_id, | |||
| # :created_on=>reply.created_on | |||
| # } | |||
| # end | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 1 | |||
| #删除 | |||
| data.each do |reply| | |||
| if reply[:id] == blog_reply.id | |||
| data.delete(reply) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| #增加 | |||
| opt = { | |||
| :id=>blog_reply.id, | |||
| :parent_id=>blog_reply.parent_id, | |||
| :created_on=>blog_reply.created_on | |||
| } | |||
| data.insert(0,opt) | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| def delete_blog_replys_cache(id) | |||
| key = 'blog_reply:'+id.to_s | |||
| Rails.cache.delete(key) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,161 @@ | |||
| class UserCache | |||
| class<<self | |||
| def user_cache(id) | |||
| key = "user:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = User.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_user_cache(id,user) | |||
| key = "user:"+id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| #直接存数据库对象 | |||
| data = User.find(id) rescue nil | |||
| if data | |||
| Rails.cache.write(key,data) | |||
| end | |||
| else | |||
| Rails.cache.write(key,user) | |||
| end | |||
| end | |||
| #-----------------------------收藏的班级 | |||
| def user_favorite_courses_cache(user_id) | |||
| key = "user_favorite_courses:"+user_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| user = User.find(user_id) | |||
| courses = user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc") | |||
| courses.each do |course| | |||
| data << { | |||
| :id=>course.id, | |||
| #:updated_at=>course.a | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_user_favorite_courses_cache(user_id,course_id,type) | |||
| key = "user_favorite_courses:"+user_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # user = User.find(user_id) | |||
| # courses = user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc") | |||
| # courses.each do |course| | |||
| # data << { | |||
| # :id=>course.id, | |||
| # #:updated_at=>course.a | |||
| # } | |||
| # end | |||
| # | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type ==0 | |||
| #增加 | |||
| data << { | |||
| :id=>course_id, | |||
| #:updated_at=>info.updated_at | |||
| } | |||
| elsif type == 1 | |||
| #删除 | |||
| data.each do |course| | |||
| if course[:id] == course_id | |||
| data.delete(course) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| # data.each_with_index do |course,index| | |||
| # if course[:id] == course_id | |||
| # data[index] = data[index].merge(opt) | |||
| # break | |||
| # end | |||
| # end | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| #-----------------------------收藏的项目 | |||
| def user_favorite_projects_cache(user_id) | |||
| key = "user_favorite_projects:"+user_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| data = [] | |||
| user = User.find(user_id) | |||
| projects = user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc") | |||
| projects.each do |project| | |||
| data << { | |||
| :id=>project.id, | |||
| #:updated_at=>project.a | |||
| } | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| data | |||
| end | |||
| #更新 | |||
| def update_user_favorite_projects_cache(user_id,project_id,type,opt={}) | |||
| key = "user_favorite_projects:"+user_id.to_s | |||
| data = Rails.cache.read(key) | |||
| if data.nil? | |||
| # data = [] | |||
| # user = User.find(user_id) | |||
| # projects = user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc") | |||
| # projects.each do |project| | |||
| # data << { | |||
| # :id=>project.id, | |||
| # #:updated_at=>project.a | |||
| # } | |||
| # end | |||
| # | |||
| # Rails.cache.write(key,data) | |||
| else | |||
| if type == 0 | |||
| #增加 | |||
| data << { | |||
| :id=>project_id, | |||
| #:updated_at=>info.updated_at | |||
| } | |||
| elsif type == 1 | |||
| #删除 | |||
| data.each do |project| | |||
| if project[:id] == project_id | |||
| data.delete(project) | |||
| break | |||
| end | |||
| end | |||
| else | |||
| # data.each_with_index do |project,index| | |||
| # if project[:id] == project_id | |||
| # data[index] = data[index].merge(opt) | |||
| # break | |||
| # end | |||
| # end | |||
| end | |||
| Rails.cache.write(key,data) | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -308,8 +308,10 @@ class AdminController < ApplicationController | |||
| if @course.is_excellent == 1 || @course.excellent_option == 1 | |||
| @course.update_column('is_excellent', 0) | |||
| @course.update_column('excellent_option', 0) | |||
| CourseCache.update_excelletn_courses_cache(@course.id,2,{}) | |||
| else | |||
| @course.update_column('is_excellent', 1) | |||
| CourseCache.update_excelletn_courses_cache(@course.id,1,{}) | |||
| end | |||
| respond_to do |format| | |||
| format.js | |||
| @@ -324,6 +326,7 @@ class AdminController < ApplicationController | |||
| if @course.is_excellent == 1 || @course.excellent_option == 1 | |||
| @course.update_column('is_excellent', 0) | |||
| @course.update_column('excellent_option', 0) | |||
| CourseCache.update_excelletn_courses_cache(@course.id,2,{}) | |||
| end | |||
| end | |||
| respond_to do |format| | |||
| @@ -26,7 +26,8 @@ class BlogsController < ApplicationController | |||
| @type = 2 | |||
| @topics.each do |topic| | |||
| topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count) | |||
| # topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count) | |||
| topic[:infocount] = get_praise_num(topic) + ReplyCache.blog_replys_cache(topic.id).count | |||
| if topic[:infocount] < 0 | |||
| topic[:infocount] = 0 | |||
| end | |||
| @@ -636,8 +636,16 @@ class CoursesController < ApplicationController | |||
| def private_or_public | |||
| if @course.is_public == 0 | |||
| @course.update_attributes(:is_public => 1) | |||
| #更新精品课程的缓存 | |||
| if @course.is_excellent == 1 || @course.excellent_option == 1 | |||
| CourseCache.update_excelletn_courses_cache(@course.id,1,{}) | |||
| end | |||
| else | |||
| @course.update_attributes(:is_public => 0) | |||
| #更新精品课程的缓存 | |||
| if @course.is_excellent == 1 || @course.excellent_option == 1 | |||
| CourseCache.update_excelletn_courses_cache(@course.id,2,{}) | |||
| end | |||
| end | |||
| if @course.is_public == 0 | |||
| course_status = CourseStatus.find_by_course_id(@course.id) | |||
| @@ -1069,6 +1077,58 @@ class CoursesController < ApplicationController | |||
| redirect_to course_url(@course, type: params[:type], page: params[:page]) | |||
| end | |||
| # def show | |||
| # # 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除 | |||
| # # if @course.is_delete == 1 && !User.current.admin? | |||
| # # render_403 | |||
| # # return | |||
| # # end | |||
| # #更新创建课程消息状态 | |||
| # course_request_messages = CourseMessage.where(:user_id => User.current.id, :course_id => @course.id, :course_message_type => ["CourseRequestDealResult", "Course"], :viewed => false) | |||
| # course_request_messages.update_all(:viewed => true) | |||
| # | |||
| # # create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0) | |||
| # # create_course_messages.update_all(:viewed => true) | |||
| # | |||
| # #更新申请结果反馈消息的状态 | |||
| # # course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false) | |||
| # # course_request_messages.update_all(:viewed => true) | |||
| # | |||
| # course_activities = @course.course_activities | |||
| # @canShowRealName = User.current.member_of_course? @course | |||
| # @page = params[:page] ? params[:page].to_i + 1 : 0 | |||
| # if params[:type].present? | |||
| # case params[:type] | |||
| # when "homework" | |||
| # @course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").order('updated_at desc') | |||
| # when "news" | |||
| # @course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc') | |||
| # when "message" | |||
| # @course_activities = course_activities.where("course_act_type = 'Message'").order('updated_at desc') | |||
| # when "poll" | |||
| # @course_activities = course_activities.where("course_act_type = 'Poll'").order('updated_at desc') | |||
| # when "attachment" | |||
| # @course_activities = course_activities.where("course_act_type = 'Attachment'").order('updated_at desc') | |||
| # when "journalsForMessage" | |||
| # @course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc') | |||
| # else | |||
| # @course_activities = course_activities.order('updated_at desc') | |||
| # end | |||
| # else | |||
| # @course_activities = course_activities.order('updated_at desc') | |||
| # end | |||
| # @course_activities_count = @course_activities.count | |||
| # @course_activities = @course_activities.limit(10).offset(@page * 10) | |||
| # @type = params[:type] | |||
| # | |||
| # @left_nav_type = 1 | |||
| # respond_to do |format| | |||
| # format.js | |||
| # format.html{render :layout => 'base_courses'} | |||
| # format.api | |||
| # end | |||
| # end | |||
| def show | |||
| # 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除 | |||
| # if @course.is_delete == 1 && !User.current.admin? | |||
| @@ -1086,31 +1146,61 @@ class CoursesController < ApplicationController | |||
| # course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false) | |||
| # course_request_messages.update_all(:viewed => true) | |||
| course_activities = @course.course_activities | |||
| course_activities = CourseCache.course_acts_cache(@course.id) | |||
| @canShowRealName = User.current.member_of_course? @course | |||
| @page = params[:page] ? params[:page].to_i + 1 : 0 | |||
| if params[:type].present? | |||
| case params[:type] | |||
| when "homework" | |||
| @course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").order('updated_at desc') | |||
| course_activities = course_activities.select{|act| | |||
| if act[:course_act_type] == 'HomeworkCommon' | |||
| act | |||
| end | |||
| } | |||
| when "news" | |||
| @course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc') | |||
| #@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 | |||
| } | |||
| when "message" | |||
| @course_activities = course_activities.where("course_act_type = 'Message'").order('updated_at desc') | |||
| #@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} | |||
| when "poll" | |||
| @course_activities = course_activities.where("course_act_type = 'Poll'").order('updated_at desc') | |||
| #@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 | |||
| } | |||
| when "attachment" | |||
| @course_activities = course_activities.where("course_act_type = 'Attachment'").order('updated_at desc') | |||
| #@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 | |||
| } | |||
| when "journalsForMessage" | |||
| @course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc') | |||
| #@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 | |||
| } | |||
| else | |||
| @course_activities = course_activities.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.order('updated_at desc') | |||
| @course_activities = course_activities.sort { |a,b| b[:updated_at].to_i <=> a[:updated_at].to_i} | |||
| end | |||
| @course_activities_count = @course_activities.count | |||
| @course_activities = @course_activities.limit(10).offset(@page * 10) | |||
| @course_activities = @course_activities[@page*10..(@page+1)*10-1] | |||
| @type = params[:type] | |||
| @left_nav_type = 1 | |||
| @@ -1304,6 +1394,7 @@ class CoursesController < ApplicationController | |||
| #删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到 | |||
| def destroy | |||
| @course.delete! | |||
| CourseCache.update_course_act_updated_at_to_0_cache(@course.id) | |||
| @course = nil | |||
| redirect_to user_url(User.current) | |||
| end | |||
| @@ -600,6 +600,7 @@ class FilesController < ApplicationController | |||
| end | |||
| attachment.description = params[:description] | |||
| attachment.save | |||
| AttachmentsCache.update_course_attachments_cache(@course.id,attachment.id,0,{}) | |||
| end | |||
| end | |||
| if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) | |||
| @@ -14,6 +14,7 @@ class HomeworkCommonController < ApplicationController | |||
| #unless params[:page] | |||
| # update_homework_time(@course.homework_commons) | |||
| #end | |||
| search_ex = params[:search].to_s.strip.downcase | |||
| search = "%#{params[:search].to_s.strip.downcase}%" | |||
| @new_homework = HomeworkCommon.new | |||
| @new_homework.homework_detail_manual = HomeworkDetailManual.new | |||
| @@ -22,10 +23,33 @@ class HomeworkCommonController < ApplicationController | |||
| @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) | |||
| if @is_teacher | |||
| #@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) | |||
| @homework_commons = @course.homework_commons.where("name like '%#{search}%'").order("created_at desc") | |||
| #缓存之前的 | |||
| #@homework_commons = @course.homework_commons.where("name like '%#{search}%'").order("created_at desc") | |||
| @homework_commons = CourseCache.course_homeworks_cache(@course.id) | |||
| @homework_commons = @homework_commons.select{|homework| | |||
| if homework[:name].match(search_ex) | |||
| homework | |||
| end | |||
| } | |||
| else | |||
| #@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) | |||
| @homework_commons = @course.homework_commons.where("name like '%#{search}%' and publish_time <= '#{Date.today}'").order("created_at desc") | |||
| #缓存之前的 | |||
| #@homework_commons = @course.homework_commons.where("name like '%#{search}%' and publish_time <= '#{Date.today}'").order("created_at desc") | |||
| @homework_commons = CourseCache.course_homeworks_cache(@course.id) | |||
| @homework_commons = @homework_commons.select{|homework| | |||
| if homework[:name].match(search_ex) && homework[:publish_time] | |||
| if homework[:publish_time].class == String | |||
| homework[:publish_time] = Date.parse(homework[:publish_time]) | |||
| end | |||
| if homework[:publish_time] <= Date.today | |||
| homework | |||
| else | |||
| end | |||
| end | |||
| } | |||
| end | |||
| #update_homework_time @homework_commons | |||
| @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) | |||
| @@ -33,6 +57,16 @@ class HomeworkCommonController < ApplicationController | |||
| @homeworks = paginateHelper @homework_commons,10 | |||
| #设置at已读 | |||
| #这10个需要取数据库 | |||
| homework_ids = @homeworks.map{|h|h[:id]} | |||
| # @homeworks = HomeworkCommon.find(homework_ids) | |||
| # @homeworks = @homeworks.sort!{|a,b| b.created_at <=> a.created_at } | |||
| @homeworks = [] | |||
| homework_ids.each do |id| | |||
| @homeworks << HomeworkCommonCache.homework_common_cache(id) | |||
| end | |||
| @homeworks.each do |homework| | |||
| # homework.journals_for_messages.each do |j| | |||
| # User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} | |||
| @@ -74,11 +108,18 @@ class HomeworkCommonController < ApplicationController | |||
| def update | |||
| if params[:homework_common] | |||
| if @homework.name != params[:homework_common][:name] | |||
| CourseCache.update_course_homeworks_cache(@homework.course.id,@homework.id,2,{:name=>params[:homework_common][:name]}) | |||
| end | |||
| @homework.name = params[:homework_common][:name] | |||
| @homework.description = params[:homework_common][:description] | |||
| if params[:homework_common][:publish_time] == "" | |||
| @homework.publish_time = Date.today | |||
| CourseCache.update_course_homeworks_cache(@homework.course.id,@homework.id,2,{:publish_time=>@homework.publish_time}) | |||
| else | |||
| if @homework.publish_time != params[:homework_common][:publish_time] | |||
| CourseCache.update_course_homeworks_cache(@homework.course.id,@homework.id,2,{:publish_time=>params[:homework_common][:publish_time]}) | |||
| end | |||
| @homework.publish_time = params[:homework_common][:publish_time] | |||
| end | |||
| homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new | |||
| @@ -233,8 +233,11 @@ class MembersController < ApplicationController | |||
| role_ids = params[:membership][:role_ids] | |||
| #role = Role.find(params[:membership][:role_ids]) | |||
| # 这里的判断只能通过角色名,可以弄成常量 | |||
| course_count = CourseCache.course_count_cache(@course.id) | |||
| if role_ids && role_ids.include?("10") | |||
| StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id) | |||
| #学生数+1 | |||
| CourseCache.update_course_count_cache(@course.id,{:student_num=>course_count[:student_num]+1}) | |||
| end | |||
| #给新成员和老师发送加入课程的消息,发送者id放在CourseMessage的course_message_id字段中 | |||
| @@ -245,6 +248,12 @@ class MembersController < ApplicationController | |||
| CourseMessage.create(:user_id => User.current.id, :course_message_id => user_id, :course_id => @course.id, :course_message_type => "JoinCourse",:content => role, :viewed => false, :status => 1) | |||
| members << member | |||
| if role_ids && (role_ids.include?("7") || role_ids.include?("9")) | |||
| #学生数+1 | |||
| CourseCache.update_course_count_cache(@course.id,{:teacher_num=>course_count[:teacher_num]+1}) | |||
| end | |||
| #user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id) | |||
| if (params[:membership][:role_ids]) | |||
| role = Role.find(params[:membership][:role_ids][0]) | |||
| @@ -324,23 +333,56 @@ class MembersController < ApplicationController | |||
| end | |||
| elsif @course | |||
| if params[:membership] | |||
| @member.role_ids = params[:membership][:role_ids] | |||
| has_stu = false | |||
| if @member.role_ids.include?(10) | |||
| has_student = true | |||
| end | |||
| has_teacher = false | |||
| if @member.role_ids.include?(7) || @member.role_ids.include?(9) | |||
| has_teacher = true | |||
| end | |||
| @member.role_ids = params[:membership][:role_ids] | |||
| if (params[:membership][:role_ids]) | |||
| role = Role.find(params[:membership][:role_ids][0]) | |||
| # 这里的判断只能通过角色名,可以弄成常量 | |||
| attrs = params[:membership].dup | |||
| role_ids = attrs.delete(:role_ids) | |||
| course_count = CourseCache.course_count_cache(@course.id) | |||
| if role_ids && role_ids.include?("10") | |||
| StudentsForCourse.create(:student_id => @member.user_id, :course_id =>@course.id) | |||
| if !has_student | |||
| #学生数+1 | |||
| CourseCache.update_course_count_cache(@course.id,{:student_num=>course_count[:student_num]+1}) | |||
| end | |||
| else | |||
| joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id) | |||
| joined.each do |join| | |||
| join.destroy | |||
| end | |||
| @member.course_group_id = 0 | |||
| if has_student | |||
| #学生数-1 | |||
| CourseCache.update_course_count_cache(@course.id,{:student_num=>course_count[:student_num]-1}) | |||
| end | |||
| end | |||
| if role_ids && (role_ids.include?("7") || role_ids.include?("9")) | |||
| if !has_teacher | |||
| #教师数+1 | |||
| CourseCache.update_course_count_cache(@course.id,{:teacher_num=>course_count[:teacher_num]+1}) | |||
| end | |||
| else | |||
| if has_teacher | |||
| #教师数-1 | |||
| CourseCache.update_course_count_cache(@course.id,{:teacher_num=>course_count[:teacher_num]-1}) | |||
| end | |||
| end | |||
| if role.allowed_to?(:is_manager) | |||
| @courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id) | |||
| @courseInfo.save | |||
| @@ -61,12 +61,12 @@ class PraiseTreadController < ApplicationController | |||
| end | |||
| return | |||
| end | |||
| @pt.delete if !@pt.nil? | |||
| @pt.destroy if !@pt.nil? | |||
| #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 | |||
| @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first | |||
| @ptc.minus(1) if !@ptc.nil? | |||
| if @ptc.praise_num == 0 | |||
| @ptc.delete | |||
| @ptc.destroy | |||
| end | |||
| end | |||
| @@ -310,21 +310,63 @@ class ProjectsController < ApplicationController | |||
| @author = params[:user_id].blank? ? nil : User.active.find(params[:user_id]) | |||
| @page = params[:page] ? params[:page].to_i + 1 : 0 | |||
| # 根据私密性,取出符合条件的所有数据 | |||
| forge_activities = ProjectCache.project_acts_cache(@project.id) | |||
| if User.current.member_of?(@project) || User.current.admin? | |||
| case params[:type] | |||
| when nil | |||
| @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| #@events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| #所有的按updated_at排序 | |||
| forge_activities = forge_activities.sort { |a,b| b['updated_at'].to_i <=> a['updated_at'].to_i} | |||
| @events_pages = forge_activities[@page*10..(@page+1)*10-1] | |||
| when 'issue' | |||
| @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| #@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| forge_activities = forge_activities.select{|act| | |||
| if act['forge_act_type'] == 'Issue' | |||
| act | |||
| end | |||
| } | |||
| forge_activities = forge_activities.sort { |a,b| b['updated_at'].to_i <=> a['updated_at'].to_i} | |||
| @events_pages = forge_activities[@page*10..(@page+1)*10-1] | |||
| when 'news' | |||
| @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| #@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| forge_activities = forge_activities.select{|act| | |||
| if act['forge_act_type'] == 'News' | |||
| act | |||
| end | |||
| } | |||
| forge_activities = forge_activities.sort { |a,b| b['updated_at'].to_i <=> a['updated_at'].to_i} | |||
| @events_pages = forge_activities[@page*10..(@page+1)*10-1] | |||
| when 'message' | |||
| @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| #@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| forge_activities = forge_activities.select{|act| | |||
| if act['forge_act_type'] == 'Message' | |||
| act | |||
| end | |||
| } | |||
| forge_activities = forge_activities.sort { |a,b| b['updated_at'].to_i <=> a['updated_at'].to_i} | |||
| @events_pages = forge_activities[@page*10..(@page+1)*10-1] | |||
| when 'attachment' | |||
| @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Attachment'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| #@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Attachment'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) | |||
| forge_activities = forge_activities.select{|act| | |||
| if act['forge_act_type'] == 'Attachment' | |||
| act | |||
| end | |||
| } | |||
| forge_activities = forge_activities.sort { |a,b| b['updated_at'].to_i <=> a['updated_at'].to_i} | |||
| @events_pages = forge_activities[@page*10..(@page+1)*10-1] | |||
| end | |||
| else | |||
| @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10); | |||
| if @project.is_public == 1 | |||
| forge_activities = forge_activities.sort { |a,b| b['created_at'].to_i <=> a['created_at'].to_i} | |||
| @events_pages = forge_activities[@page*10..(@page+1)*10-1] | |||
| else | |||
| @events_pages = [] | |||
| end | |||
| #@events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10); | |||
| end | |||
| @type = params[:type] | |||
| # 版本库统计图 | |||
| @@ -1026,6 +1026,7 @@ class StudentWorkController < ApplicationController | |||
| @homework.student_works.each do |student_work| | |||
| set_final_score @homework,student_work | |||
| student_work.save | |||
| CourseCache.update_course_heroes_cache(@homework.course.id,student_work.user.id,0,{}) | |||
| end | |||
| end | |||
| @@ -1054,6 +1055,7 @@ class StudentWorkController < ApplicationController | |||
| @homework.student_works.each do |student_work| | |||
| set_final_score @homework,student_work | |||
| student_work.save | |||
| CourseCache.update_course_heroes_cache(@homework.course.id,student_work.user.id,0,{}) | |||
| end | |||
| @user_activity_id = params[:user_activity_id].to_i | |||
| @hw_status = params[:hw_status].to_i | |||
| @@ -421,15 +421,21 @@ class UsersController < ApplicationController | |||
| member = Course.find(@msg.course_id).members.where(:user_id=>apply_user.id).all[0] | |||
| member.role_ids = integer_ids | |||
| #删除为学生的记录 | |||
| course_count = CourseCache.course_count_cache(@msg.course_id) | |||
| unless member.role_ids.include?(10) | |||
| joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@msg.course_id) | |||
| joined.each do |join| | |||
| join.delete | |||
| end | |||
| #学生数-1 | |||
| CourseCache.update_course_count_cache(@msg.course_id,{:student_num=>course_count[:student_num]-1}) | |||
| end | |||
| member.course_group_id = 0 | |||
| member.save | |||
| #老师数+1 | |||
| CourseCache.update_course_count_cache(@msg.course_id,{:teacher_num=>course_count[:teacher_num]+1}) | |||
| CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) | |||
| @msg.update_attributes(:status=>1,:viewed=>1) | |||
| else | |||
| @@ -1502,16 +1508,41 @@ class UsersController < ApplicationController | |||
| #显示更多用户课程 | |||
| def user_courses4show | |||
| @page = params[:page].to_i + 1 | |||
| @courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10).offset(@page * 10) | |||
| @all_count = @user.favorite_courses.visible.where("is_delete =?", 0).count | |||
| # @page = params[:page].to_i + 1 | |||
| # @courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10).offset(@page * 10) | |||
| # @all_count = @user.favorite_courses.visible.where("is_delete =?", 0).count | |||
| @page = params[:page].to_i+1 | |||
| @courses = get_user_favorite_courses(@user.id,@page) | |||
| allcourses = UserCache.user_favorite_courses_cache(@user.id) | |||
| allcourses = allcourses.select{ |c| | |||
| if CourseCache.course_act_updated_at_cache(c[:id]).to_i != 0 | |||
| c | |||
| end | |||
| } | |||
| @all_count = allcourses.count | |||
| end | |||
| #显示更多用户项目 | |||
| def user_projects4show | |||
| @page = params[:page].to_i + 1 | |||
| @projects = @user.favorite_projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10).offset(@page * 10) | |||
| @all_count = @user.favorite_projects.visible.count | |||
| # @page = params[:page].to_i + 1 | |||
| # @projects = @user.favorite_projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10).offset(@page * 10) | |||
| # @all_count = @user.favorite_projects.visible.count | |||
| @page = params[:page].to_i+1 | |||
| @projects = get_user_favorite_projects(@user.id,@page) | |||
| allprojects = UserCache.user_favorite_projects_cache(@user.id) | |||
| allprojects = allprojects.select{ |p| | |||
| if ProjectCache.project_act_updated_at_cache(p[:id]).to_i != 0 | |||
| p | |||
| end | |||
| } | |||
| @all_count = allprojects.count | |||
| end | |||
| def user_course_activities | |||
| @@ -3490,6 +3521,14 @@ class UsersController < ApplicationController | |||
| member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") | |||
| end | |||
| unless member.empty? | |||
| #收藏、取消收藏 更新缓存 | |||
| if params[:project] | |||
| UserCache.update_user_favorite_projects_cache(@user.id,@project.id,member.first.is_collect) | |||
| elsif params[:course] | |||
| UserCache.update_user_favorite_courses_cache(@user.id,@course.id,member.first.is_collect) | |||
| end | |||
| member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) | |||
| end | |||
| if @project | |||
| @@ -420,6 +420,9 @@ module ApiHelper | |||
| if course_activity | |||
| course_activity.updated_at = Time.now | |||
| course_activity.save | |||
| #更新缓存 | |||
| CourseCache.update_course_acts_cache(course_activity.course.id,id,type.to_s,{:updated_at=>course_activity.updated_at}) | |||
| CourseCache.update_course_act_updated_at_cache(course_activity.course.id) | |||
| end | |||
| end | |||
| #首页动态更新 | |||
| @@ -436,6 +439,8 @@ module ApiHelper | |||
| if forge_activity | |||
| forge_activity.updated_at = Time.now | |||
| forge_activity.save | |||
| ProjectCache.update_project_acts_cache(forge_activity.project.id,id,type.to_s,{'updated_at'=>forge_activity.updated_at.to_i}) | |||
| ProjectCache.update_project_act_updated_at_cache(forge_activity.project.id) | |||
| end | |||
| end | |||
| #组织动态更新 | |||
| @@ -280,7 +280,7 @@ module ApplicationHelper | |||
| case type | |||
| when "HomeworkCommon" | |||
| if course_contributor_score.nil? | |||
| CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1) | |||
| course_contributor_score = CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1) | |||
| else | |||
| score = course_contributor_score.homework_journal_num.to_i + 1 | |||
| course_contributor_score.update_column(:homework_journal_num, score) | |||
| @@ -288,47 +288,69 @@ module ApplicationHelper | |||
| # 课程留言 | |||
| when "Course" | |||
| if course_contributor_score.nil? | |||
| CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1) | |||
| course_contributor_score = CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1) | |||
| else | |||
| score = course_contributor_score.journal_num.to_i + 1 | |||
| course_contributor_score.update_column(:journal_num, score) | |||
| end | |||
| when "Message" | |||
| if course_contributor_score.nil? | |||
| CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1) | |||
| course_contributor_score = CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1) | |||
| else | |||
| score = course_contributor_score.message_num.to_i + 1 | |||
| course_contributor_score.update_column(:message_num, score) | |||
| end | |||
| when "MessageReply" | |||
| if course_contributor_score.nil? | |||
| CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1) | |||
| course_contributor_score = CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1) | |||
| else | |||
| score = course_contributor_score.message_reply_num.to_i + 1 | |||
| course_contributor_score.update_column(:message_reply_num, score) | |||
| end | |||
| when "NewReply" | |||
| if course_contributor_score.nil? | |||
| CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1) | |||
| course_contributor_score = CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1) | |||
| else | |||
| score = course_contributor_score.news_reply_num.to_i + 1 | |||
| course_contributor_score.update_column(:news_reply_num, score) | |||
| end | |||
| when "News" | |||
| if course_contributor_score.nil? | |||
| CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1) | |||
| course_contributor_score = CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1) | |||
| else | |||
| score = course_contributor_score.news_num.to_i + 1 | |||
| course_contributor_score.update_column(:news_num, score) | |||
| end | |||
| when "Attachment" | |||
| if course_contributor_score.nil? | |||
| CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1) | |||
| course_contributor_score = CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1) | |||
| else | |||
| score = course_contributor_score.resource_num.to_i + 1 | |||
| course_contributor_score.update_column(:resource_num, score) | |||
| end | |||
| end | |||
| opt = { | |||
| :id=>course_contributor_score.id, | |||
| :user_id=>course_contributor_score.user_id, | |||
| :resource_num=>course_contributor_score.resource_num, | |||
| :message_num=>course_contributor_score.message_num, | |||
| :message_reply_num=>course_contributor_score.message_reply_num, | |||
| :journal_num=>course_contributor_score.journal_num, | |||
| :homework_journal_num=>course_contributor_score.homework_journal_num, | |||
| :news_reply_num=>course_contributor_score.news_reply_num, | |||
| :news_num=>course_contributor_score.news_num, | |||
| :total_score=>course_contributor_score.resource_num.to_i * 5 + course_contributor_score.message_num.to_i * 2 + | |||
| course_contributor_score.message_reply_num.to_i * 1 + course_contributor_score.journal_num.to_i * 1 + | |||
| + course_contributor_score.homework_journal_num.to_i * 1 + course_contributor_score.news_reply_num.to_i * 1 + | |||
| course_contributor_score.news_num.to_i * 1 | |||
| } | |||
| #更新缓存 | |||
| student = StudentsForCourse.where("course_id = #{course_id} and student_id = #{user_id} ").first | |||
| unless student.nil? | |||
| CourseCache.update_course_contributor_score_cache(course_id,user_id,opt) | |||
| end | |||
| end | |||
| # 删除某条记录相应减少课程统计数 | |||
| @@ -372,6 +394,29 @@ module ApplicationHelper | |||
| course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score) | |||
| end | |||
| end | |||
| if course_contributor_score | |||
| opt = { | |||
| :id=>course_contributor_score.id, | |||
| :user_id=>course_contributor_score.user_id, | |||
| :resource_num=>course_contributor_score.resource_num, | |||
| :message_num=>course_contributor_score.message_num, | |||
| :message_reply_num=>course_contributor_score.message_reply_num, | |||
| :journal_num=>course_contributor_score.journal_num, | |||
| :homework_journal_num=>course_contributor_score.homework_journal_num, | |||
| :news_reply_num=>course_contributor_score.news_reply_num, | |||
| :news_num=>course_contributor_score.news_num, | |||
| :total_score=>course_contributor_score.resource_num.to_i * 5 + course_contributor_score.message_num.to_i * 2 + | |||
| course_contributor_score.message_reply_num.to_i * 1 + course_contributor_score.journal_num.to_i * 1 + | |||
| + course_contributor_score.homework_journal_num.to_i * 1 + course_contributor_score.news_reply_num.to_i * 1 + | |||
| course_contributor_score.news_num.to_i * 1 | |||
| } | |||
| #更新缓存 | |||
| student = StudentsForCourse.where("course_id = #{course_id} and student_id = #{user_id} ").first | |||
| unless student.nil? | |||
| CourseCache.update_course_contributor_score_cache(course_id,user_id,opt) | |||
| end | |||
| end | |||
| end | |||
| # Added by young | |||
| @@ -3223,6 +3268,9 @@ int main(int argc, char** argv){ | |||
| if course_activity | |||
| course_activity.updated_at = Time.now | |||
| course_activity.save | |||
| #更新缓存 | |||
| CourseCache.update_course_acts_cache(course_activity.course.id,id,type.to_s,{:updated_at=>course_activity.updated_at}) | |||
| CourseCache.update_course_act_updated_at_cache(course_activity.course.id) | |||
| end | |||
| end | |||
| #首页动态更新 | |||
| @@ -3239,6 +3287,8 @@ int main(int argc, char** argv){ | |||
| if forge_activity | |||
| forge_activity.updated_at = Time.now | |||
| forge_activity.save | |||
| ProjectCache.update_project_acts_cache(forge_activity.project.id,id,type.to_s,{'updated_at'=>forge_activity.updated_at.to_i}) | |||
| ProjectCache.update_project_act_updated_at_cache(forge_activity.project.id) | |||
| end | |||
| end | |||
| #组织动态更新 | |||
| @@ -3404,6 +3454,17 @@ def get_reply_parents parents_rely, comment | |||
| parents_rely | |||
| end | |||
| def get_reply_parents_ex parents_rely,comment,type | |||
| if type == 'News' | |||
| parents_rely = ReplyCache.get_news_reply_parents_cache(comment.commented_id,comment.id) | |||
| elsif type == 'HomeworkCommon' | |||
| parents_rely = ReplyCache.get_homework_reply_parents_cache(comment.jour_id,comment.id) | |||
| else | |||
| parents_rely = get_reply_parents parents_rely, comment | |||
| end | |||
| end | |||
| #获取回复的所有父节点(不包括根节点) | |||
| def get_reply_parents_no_root parents_rely, comment | |||
| if !comment.parent.nil? && !comment.parent.parent.nil? | |||
| @@ -3413,6 +3474,19 @@ def get_reply_parents_no_root parents_rely, comment | |||
| parents_rely | |||
| end | |||
| #获取回复的所有父节点(不包括根节点) | |||
| def get_reply_parents_no_root_ex parents_rely, comment,type | |||
| if type == 'Message' | |||
| parents_rely = ReplyCache.get_message_reply_parents_cache(comment.root_id,comment.id) | |||
| elsif type == 'JournalsForMessage' | |||
| parents_rely = ReplyCache.get_leave_reply_parents_cache(comment.root_id,comment.id) | |||
| elsif type == 'BlogComment' | |||
| parents_rely = ReplyCache.get_blog_reply_parents_cache(comment.root_id,comment.id) | |||
| else | |||
| parents_rely = get_reply_parents_no_root parents_rely, comment | |||
| end | |||
| end | |||
| def get_all_children_ex result, jour | |||
| if jour.kind_of? Message | |||
| jour.children.includes(:author, :praise_tread_cache).each do |jour_child| | |||
| @@ -3746,3 +3820,58 @@ def homework_type_option | |||
| type | |||
| end | |||
| #获取用户的收藏的课程 | |||
| def get_user_favorite_courses(user_id,page) | |||
| courses = UserCache.user_favorite_courses_cache(user_id) | |||
| courses = courses.select{ |c| | |||
| if CourseCache.course_act_updated_at_cache(c[:id]).to_i != 0 | |||
| c | |||
| end | |||
| } | |||
| courses = courses.sort!{ |a,b| CourseCache.course_act_updated_at_cache(b[:id]).to_i <=> CourseCache.course_act_updated_at_cache(a[:id]).to_i } | |||
| courses[10*page..(page+1)*10-1] | |||
| end | |||
| #获取用户的收藏的项目 | |||
| def get_user_favorite_projects(user_id,page) | |||
| projects = UserCache.user_favorite_projects_cache(user_id) | |||
| projects = projects.select{ |p| | |||
| if ProjectCache.project_act_updated_at_cache(p[:id]).to_i != 0 | |||
| p | |||
| end | |||
| } | |||
| projects = projects.sort!{ |a,b| ProjectCache.project_act_updated_at_cache(b[:id]).to_i <=> ProjectCache.project_act_updated_at_cache(a[:id]).to_i } | |||
| projects[10*page..(page+1)*10-1] | |||
| end | |||
| #根据type类型获取帖子对象 | |||
| def get_act_by_cache(id,type) | |||
| case type | |||
| when 'Message' | |||
| MessagesCache.message_cache(id) | |||
| when 'News' | |||
| NewsCache.news_cache(id) | |||
| when 'Issue' | |||
| IssueCache.issue_cache(id) | |||
| when 'HomeworkCommon' | |||
| HomeworkCommonCache.homework_common_cache(id) | |||
| when 'Comment' | |||
| CommentCache.comment_cache(id) | |||
| when 'JournalsForMessage' | |||
| JournalsForMessageCache.journalsformessage_cache(id) | |||
| else | |||
| className = type.classify.constantize | |||
| className.find(id) rescue nil | |||
| end | |||
| end | |||
| @@ -16,7 +16,8 @@ module CoursesHelper | |||
| # 推荐的精品课程 | |||
| def excellent_course_recommend new_course | |||
| q = "%#{new_course.name.strip}%" | |||
| result = find_excelletn_course(q, new_course) | |||
| #result = find_excelletn_course(q, new_course) | |||
| result = find_excelletn_course_ex(q, new_course) | |||
| end | |||
| # 查询符合条件的精品课程 | |||
| @@ -40,6 +41,29 @@ module CoursesHelper | |||
| return excellent_courses | |||
| end | |||
| def find_excelletn_course_ex keywords, current_course | |||
| # 获取tag匹配结果ID | |||
| a_tags = [] | |||
| courses = CourseCache.excelletn_courses_cache | |||
| courses = courses.sort!{ |a,b| b[:updated_at] <=> a[:updated_at] } | |||
| courses.each do |course| | |||
| if course[:tags].any?{|value| current_course.name.include?(value.to_s)} | |||
| a_tags << course[:id] | |||
| end | |||
| end | |||
| excellent_ids = a_tags.uniq.delete_if{|i| i == current_course.id} | |||
| default_ids = courses.flatten.map { |c| c[:id] } | |||
| excellent_ids << default_ids.flatten | |||
| arr_result = excellent_ids.flatten.uniq.delete_if{|i| i == current_course.id}.first(3) | |||
| excellent_courses = Course.find(arr_result) | |||
| return excellent_courses | |||
| end | |||
| # 判断精品课程是否可见,非课程成员无法查看私有课程 | |||
| def visible_excellent_course obj | |||
| # if course.is_pu | |||
| @@ -804,14 +828,31 @@ module CoursesHelper | |||
| def visable_attachemnts_incourse course | |||
| return[] unless course | |||
| result = [] | |||
| is_teacher = User.current.allowed_to?(:as_teacher,course) | |||
| is_member = User.current.member_of_course?(course) | |||
| course.attachments.each do |attachment| | |||
| if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || User.current.allowed_to?(:as_teacher,course) || (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? | |||
| if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || is_teacher || (is_member && attachment.is_publish == 1) || User.current.admin? | |||
| result << attachment | |||
| end | |||
| end | |||
| result | |||
| end | |||
| def visable_attachemnts_incourse_ex course | |||
| return[] unless course | |||
| attachments = AttachmentsCache.course_attachments_cache(course.id) | |||
| result = [] | |||
| is_teacher = User.current.allowed_to?(:as_teacher,course) | |||
| is_member = User.current.member_of_course?(course) | |||
| attachments.each do |attachment| | |||
| if attachment[:is_public] == 1 && attachment[:is_publish] == 1 || User.current.id == attachment[:author_id] || is_teacher || (is_member && attachment[:is_publish] == 1) || User.current.admin? | |||
| result << attachment | |||
| end | |||
| end | |||
| end | |||
| def visable_course_homework course | |||
| if User.current.admin? || User.current.allowed_to?(:as_teacher,course) | |||
| homework_num = course.homework_commons.count | |||
| @@ -821,6 +862,28 @@ module CoursesHelper | |||
| homework_num | |||
| end | |||
| def visable_course_homework_ex course | |||
| homework_commons = CourseCache.course_homeworks_cache(course.id) | |||
| if User.current.admin? || User.current.allowed_to?(:as_teacher,course) | |||
| homework_num = homework_commons.count | |||
| else | |||
| homework_commons = homework_commons.select{|homework| | |||
| if homework[:publish_time] | |||
| if homework[:publish_time].class == String | |||
| homework[:publish_time] = Date.parse(homework[:publish_time]) | |||
| end | |||
| if homework[:publish_time] <= Date.today | |||
| homework | |||
| else | |||
| end | |||
| end | |||
| } | |||
| homework_num = homework_commons.count | |||
| end | |||
| homework_num | |||
| end | |||
| def zh_course_role role | |||
| if role == "TeachingAsistant" | |||
| result = l(:label_TA) | |||
| @@ -911,6 +974,18 @@ module CoursesHelper | |||
| homework_scores = Member.find_by_sql(sql_select) | |||
| end | |||
| def hero_homework_score_ex(course, score_sort_by) | |||
| homework_scores = CourseCache.course_heroes_cache(course.id) | |||
| homework_scores = homework_scores.select{|hero| | |||
| unless hero[:score].nil? | |||
| hero | |||
| end | |||
| } | |||
| homework_scores.sort! { |a,b| b[:score] <=> a[:score] } | |||
| homework_scores[0..5] | |||
| end | |||
| def contributor_course_scor(course_id) | |||
| ccs = CourseContributorScore.find_by_sql("SELECT ccs.*, (message_num*2 + message_reply_num + news_reply_num + news_num + | |||
| resource_num*5 + journal_num + homework_journal_num ) as con_score FROM `course_contributor_scores` ccs JOIN students_for_courses sfs | |||
| @@ -918,6 +993,12 @@ module CoursesHelper | |||
| con_score desc limit 6;") | |||
| end | |||
| def contributor_course_scor_ex(course_id) | |||
| ccs = CourseCache.course_contributor_score_cache(course_id) | |||
| ccs.sort! { |a,b| b[:total_score] <=> a[:total_score] } | |||
| ccs[0..5] | |||
| end | |||
| #用户在该课程是否具有某个角色 | |||
| def get_user_member_roles_course course, user, role | |||
| members = course.members.where("user_id = #{user.id}") | |||
| @@ -93,10 +93,11 @@ class Attachment < ActiveRecord::Base | |||
| @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") | |||
| before_save :files_to_final_location | |||
| after_save :act_as_course_activity | |||
| after_create :office_conver, :be_user_score,:create_attachment_ealasticsearch_index | |||
| after_save :act_as_course_activity,:update_cache_opt | |||
| after_create :office_conver, :be_user_score,:create_attachment_ealasticsearch_index,:update_cache_add | |||
| after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index | |||
| after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count, :down_course_score | |||
| before_destroy :update_cache_delete | |||
| # add by nwb | |||
| # 获取所有可公开的资源文件列表 | |||
| @@ -683,6 +684,26 @@ class Attachment < ActiveRecord::Base | |||
| down_course_score_num(self.container_id, self.author_id, "Attachment") | |||
| end | |||
| end | |||
| #更新缓存 | |||
| def update_cache_add | |||
| if self.course | |||
| AttachmentsCache.update_course_attachments_cache(self.course.id,self.id,0,{}) | |||
| end | |||
| end | |||
| def update_cache_delete | |||
| if self.course | |||
| AttachmentsCache.update_course_attachments_cache(self.course.id,self.id,1,{}) | |||
| end | |||
| end | |||
| def update_cache_opt | |||
| if self.course | |||
| AttachmentsCache.update_course_attachments_cache(self.course.id,self.id,2,{}) | |||
| end | |||
| end | |||
| end | |||
| # Delete the previous articles index in Elasticsearch | |||
| @@ -23,8 +23,8 @@ class BlogComment < ActiveRecord::Base | |||
| after_save :add_user_activity | |||
| after_update :update_activity | |||
| after_create :update_parent_time | |||
| before_destroy :destroy_user_activity | |||
| after_create :update_parent_time,:update_cache_add | |||
| before_destroy :destroy_user_activity,:update_cache_delete | |||
| scope :like, lambda {|arg| | |||
| if arg.blank? | |||
| @@ -103,4 +103,19 @@ class BlogComment < ActiveRecord::Base | |||
| # ws.comment_template self.parent.author_id, "blog_comment", self.parent_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content | |||
| # end | |||
| # end | |||
| #更新缓存二级回复 | |||
| def update_cache_add | |||
| unless self.root_id.nil? | |||
| ReplyCache.update_blog_replys_cache(self.root_id,self,0) | |||
| end | |||
| end | |||
| def update_cache_delete | |||
| unless self.root_id.nil? | |||
| ReplyCache.update_blog_replys_cache(self.root_id,self,1) | |||
| end | |||
| ReplyCache.delete_blog_replys_cache(self.id) | |||
| end | |||
| end | |||
| @@ -40,7 +40,8 @@ class Comment < ActiveRecord::Base | |||
| belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | |||
| validates_presence_of :commented, :author, :comments | |||
| safe_attributes 'comments','parent_id','reply_id','comments_count' | |||
| after_create :send_mail, :act_as_system_message, :act_as_student_score | |||
| after_create :send_mail, :act_as_system_message, :act_as_student_score,:update_cache_add | |||
| before_destroy :update_cache_delete | |||
| after_destroy :down_course_score | |||
| def act_as_system_message | |||
| @@ -119,4 +120,18 @@ class Comment < ActiveRecord::Base | |||
| self.comments | |||
| end | |||
| #更新缓存二级回复 | |||
| def update_cache_add | |||
| if self.commented_type == 'News' | |||
| ReplyCache.update_news_replys_cache(self.commented_id,self,0) | |||
| end | |||
| end | |||
| def update_cache_delete | |||
| if self.commented_type == 'News' | |||
| ReplyCache.update_news_replys_cache(self.commented_id,self,1) | |||
| end | |||
| CommentCache.delete_comment_cache(self.id) | |||
| end | |||
| end | |||
| @@ -5,8 +5,9 @@ class CourseActivity < ActiveRecord::Base | |||
| belongs_to :course | |||
| belongs_to :user | |||
| has_many :user_acts, :class_name => 'UserAcivity',:as =>:act | |||
| after_create :add_course_lead,:add_user_activity, :add_org_activity | |||
| before_destroy :destroy_user_activity, :destroy_org_activity | |||
| after_create :add_course_lead,:add_user_activity, :add_org_activity, :update_cache_add | |||
| before_destroy :destroy_user_activity, :destroy_org_activity, :update_cache_delete | |||
| after_destroy :update_cache_delete_ex | |||
| #在个人动态里面增加当前动态 | |||
| def add_user_activity | |||
| @@ -78,4 +79,22 @@ class CourseActivity < ActiveRecord::Base | |||
| message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first | |||
| end | |||
| end | |||
| #更新班级的动态缓存 | |||
| def update_cache_add | |||
| CourseCache.update_course_acts_nums_cache(self.course.id,self,0) | |||
| CourseCache.update_course_act_updated_at_cache(self.course.id) | |||
| end | |||
| #删除前更新 | |||
| def update_cache_delete | |||
| CourseCache.update_course_acts_nums_cache(self.course.id,self,1) | |||
| CourseCache.update_course_act_updated_at_cache(self.course.id) | |||
| end | |||
| #删除后更新 | |||
| def update_cache_delete_ex | |||
| CourseCache.update_course_act_updated_at_cache(self.course.id) | |||
| end | |||
| end | |||
| @@ -20,8 +20,9 @@ class ForgeActivity < ActiveRecord::Base | |||
| validates :forge_act_id,presence: true | |||
| validates :forge_act_type, presence: true | |||
| has_many :user_acts, :class_name => 'UserAcivity',:as =>:act | |||
| after_create :add_user_activity, :add_org_activity | |||
| before_destroy :destroy_user_activity, :destroy_org_activity | |||
| after_create :add_user_activity, :add_org_activity,:update_cache_add | |||
| before_destroy :destroy_user_activity, :destroy_org_activity,:update_cache_delete | |||
| after_destroy :update_cache_delete_ex | |||
| # 在个人动态里面增加当前动态 | |||
| # 版本库提交动态不显示在用户动态中 | |||
| @@ -87,4 +88,19 @@ class ForgeActivity < ActiveRecord::Base | |||
| org_acts = OrgActivity.where("org_act_type='#{self.forge_act_type.to_s}' and org_act_id = '#{self.forge_act_id}'") | |||
| org_acts.destroy_all | |||
| end | |||
| #更新项目的动态缓存 | |||
| def update_cache_add | |||
| ProjectCache.update_project_acts_nums_cache(self.project.id,self,0) | |||
| ProjectCache.update_project_act_updated_at_cache(self.project.id) | |||
| end | |||
| def update_cache_delete | |||
| ProjectCache.update_project_acts_nums_cache(self.project.id,self,1) | |||
| end | |||
| def update_cache_delete_ex | |||
| ProjectCache.update_project_act_updated_at_cache(self.project.id) | |||
| end | |||
| end | |||
| @@ -31,10 +31,11 @@ class HomeworkCommon < ActiveRecord::Base | |||
| :description => :description, | |||
| :author => :author, | |||
| :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} | |||
| after_create :act_as_activity, :send_mail,:act_as_course_message | |||
| after_update :update_activity | |||
| after_create :act_as_activity, :send_mail,:act_as_course_message,:update_cache_add | |||
| after_update :update_activity, :update_cache | |||
| after_save :act_as_course_activity | |||
| after_destroy :delete_kindeditor_assets | |||
| before_destroy :update_cache_delete | |||
| #作业类型 | |||
| def homework_type_ch | |||
| @@ -171,6 +172,20 @@ class HomeworkCommon < ActiveRecord::Base | |||
| end | |||
| end | |||
| #更新缓存 | |||
| def update_cache_add | |||
| CourseCache.update_course_homeworks_cache(self.course.id,self.id,0,{}) | |||
| end | |||
| def update_cache_delete | |||
| CourseCache.update_course_homeworks_cache(self.course.id,self.id,1,{}) | |||
| ReplyCache.delete_homework_replys_cache(self.id) | |||
| HomeworkCommonCache.delete_homework_common_cache(self.id) | |||
| end | |||
| def update_cache | |||
| HomeworkCommonCache.update_homework_common_cache(self.id,self) | |||
| end | |||
| delegate :language_name, :language, :to => :homework_detail_programing | |||
| end | |||
| @@ -91,7 +91,7 @@ class Issue < ActiveRecord::Base | |||
| after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, | |||
| act_as_at_message(:description, :author_id), :add_issues_count | |||
| after_update :be_user_score,:update_activity | |||
| after_update :be_user_score,:update_activity, :update_cache | |||
| after_destroy :down_user_score, :decrease_issues_count | |||
| # after_create :be_user_score | |||
| # end | |||
| @@ -132,6 +132,7 @@ class Issue < ActiveRecord::Base | |||
| # Should be after_create but would be called before previous after_save callbacks | |||
| after_save :after_create_from_copy | |||
| after_destroy :update_parent_attributes | |||
| before_destroy :update_cache_delete | |||
| #动态的更新 | |||
| def update_activity | |||
| @@ -1668,6 +1669,13 @@ class Issue < ActiveRecord::Base | |||
| end | |||
| def update_cache | |||
| IssueCache.update_issue_cache(self.id,self) | |||
| end | |||
| def update_cache_delete | |||
| IssueCache.delete_issue_cache(self.id) | |||
| end | |||
| end | |||
| @@ -76,11 +76,12 @@ class JournalsForMessage < ActiveRecord::Base | |||
| after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, | |||
| act_as_at_message(:notes, :user_id), :act_as_user_feedback_message, | |||
| :act_as_principal_activity, :act_as_student_score | |||
| after_create :reset_counters! | |||
| after_create :reset_counters!,:update_cache_add | |||
| #after_update :update_activity | |||
| # after_destroy :reset_counters! | |||
| after_save :be_user_score | |||
| after_destroy :down_user_score, :down_course_score | |||
| before_destroy :update_cache_delete | |||
| # default_scope { where('m_parent_id IS NULL') } | |||
| @@ -344,4 +345,28 @@ class JournalsForMessage < ActiveRecord::Base | |||
| def content_detail | |||
| self.notes | |||
| end | |||
| #更新缓存二级回复 | |||
| def update_cache_add | |||
| if self.jour_type == 'HomeworkCommon' | |||
| ReplyCache.update_homework_replys_cache(self.jour_id,self,0) | |||
| elsif self.jour_type == 'Course' | |||
| if self.root_id | |||
| ReplyCache.update_leave_replys_cache(self.root_id,self,0) | |||
| end | |||
| end | |||
| end | |||
| def update_cache_delete | |||
| if self.jour_type == 'HomeworkCommon' | |||
| ReplyCache.update_homework_replys_cache(self.jour_id,self,1) | |||
| elsif self.jour_type == 'Course' | |||
| if self.root_id | |||
| ReplyCache.update_leave_replys_cache(self.root_id,self,1) | |||
| end | |||
| end | |||
| JournalsForMessageCache.delete_journalsformessage_cache(self.id) | |||
| end | |||
| end | |||
| @@ -82,10 +82,11 @@ class Message < ActiveRecord::Base | |||
| validate :cannot_reply_to_locked_topic, :on => :create | |||
| # after_create :add_author_as_watcher, :reset_counters!, :add_boards_count | |||
| after_update :update_messages_board, :update_activity | |||
| after_update :update_messages_board, :update_activity, :update_cache | |||
| after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score | |||
| after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message, :delay_message_send | |||
| after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message, :delay_message_send, :update_cache_add | |||
| #before_save :be_user_score | |||
| before_destroy :update_cache_delete | |||
| scope :visible, lambda {|*args| | |||
| includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) | |||
| @@ -412,4 +413,26 @@ class Message < ActiveRecord::Base | |||
| def delete_org_activities | |||
| OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all | |||
| end | |||
| #更新缓存二级回复 | |||
| def update_cache_add | |||
| unless self.root_id.nil? | |||
| ReplyCache.update_message_replys_cache(self.root_id,self,0) | |||
| end | |||
| end | |||
| def update_cache_delete | |||
| Rails.logger.info("start%%%%%%%%%%%%%%%") | |||
| unless self.root_id.nil? | |||
| ReplyCache.update_message_replys_cache(self.root_id,self,1) | |||
| end | |||
| MessagesCache.delete_message_cache(self.id) | |||
| ReplyCache.delete_message_replys_cache(self.id) | |||
| Rails.logger.info("end%%%%%%%%%%%%%%%") | |||
| end | |||
| def update_cache | |||
| MessagesCache.update_message_cache(self.id,self) | |||
| end | |||
| end | |||
| @@ -65,9 +65,9 @@ class News < ActiveRecord::Base | |||
| :author_key => :author_id | |||
| acts_as_watchable | |||
| after_create :act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message,:delay_news_wechat_send,:delay_news_send | |||
| after_update :update_activity | |||
| after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score | |||
| after_create :act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message,:delay_news_wechat_send,:delay_news_send, :update_cache_add | |||
| after_update :update_activity, :update_cache | |||
| after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score, :update_cache_delete | |||
| scope :visible, lambda {|*args| | |||
| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) | |||
| @@ -249,4 +249,25 @@ class News < ActiveRecord::Base | |||
| end | |||
| end | |||
| #更新新闻数缓存 | |||
| def update_cache_add | |||
| if self.course | |||
| course_count = CourseCache.course_count_cache(self.course.id) | |||
| CourseCache.update_course_count_cache(self.course.id,{:news_count=>course_count[:news_count]+1}) | |||
| end | |||
| end | |||
| def update_cache_delete | |||
| if self.course | |||
| course_count = CourseCache.course_count_cache(self.course.id) | |||
| CourseCache.update_course_count_cache(self.course.id,{:news_count=>course_count[:news_count]-1}) | |||
| end | |||
| NewsCache.delete_news_cache(self.id) | |||
| ReplyCache.delete_news_replys_cache(self.id) | |||
| end | |||
| def update_cache | |||
| NewsCache.update_news_cache(self.id,self) | |||
| end | |||
| end | |||
| @@ -4,6 +4,8 @@ class PraiseTread < ActiveRecord::Base | |||
| belongs_to :praise_tread_object, polymorphic: true | |||
| #after_create :be_user_score | |||
| #after_destroy :down_user_score | |||
| after_create :set_praise_cache_true | |||
| before_destroy :set_praise_cache_false | |||
| include UserScoreHelper | |||
| def self.find_object_by_type_and_id(type,id) | |||
| @obj = nil | |||
| @@ -90,9 +92,19 @@ class PraiseTread < ActiveRecord::Base | |||
| end | |||
| def self.praised(activity) | |||
| self.where(praise_tread_object_id: activity.id, | |||
| praise_tread_object_type: activity.class.to_s, | |||
| user_id: User.current.id).empty? | |||
| # self.where(praise_tread_object_id: activity.id, | |||
| # praise_tread_object_type: activity.class.to_s, | |||
| # user_id: User.current.id).empty? | |||
| PraiseCache.ispraise_cache(User.current.id,activity.id,activity.class) | |||
| end | |||
| def set_praise_cache_true | |||
| PraiseCache.update_ispraise_cache(self.user_id,self.praise_tread_object_id,self.praise_tread_object_type,true) | |||
| end | |||
| def set_praise_cache_false | |||
| PraiseCache.update_ispraise_cache(self.user_id,self.praise_tread_object_id,self.praise_tread_object_type,false) | |||
| end | |||
| end | |||
| @@ -7,11 +7,13 @@ class PraiseTreadCache < ActiveRecord::Base | |||
| when 0 | |||
| self.update_attribute(:tread_num, self.tread_num.to_i + num) | |||
| when 1 | |||
| PraiseCache.update_praise_cache(self.object_id,self.object_type,{:praise_num=>self.praise_num.to_i + num}) | |||
| self.update_attribute(:praise_num, self.praise_num.to_i + num) | |||
| end | |||
| end | |||
| def minus(num) | |||
| PraiseCache.update_praise_cache(self.object_id,self.object_type,{:praise_num=>self.praise_num.to_i - num}) | |||
| self.update_attribute(:praise_num, self.praise_num.to_i - num) | |||
| end | |||
| end | |||
| @@ -497,6 +497,7 @@ class Project < ActiveRecord::Base | |||
| Project.transaction do | |||
| archive! | |||
| end | |||
| ProjectCache.update_project_act_updated_at_to_0_cache(self.id) | |||
| true | |||
| end | |||
| @@ -18,6 +18,7 @@ class StudentWork < ActiveRecord::Base | |||
| before_destroy :delete_praise | |||
| before_save :set_program_score, :set_src | |||
| after_save :update_score_cache | |||
| after_create :act_as_message | |||
| acts_as_attachable | |||
| @@ -179,4 +180,10 @@ class StudentWork < ActiveRecord::Base | |||
| self.course_messages << CourseMessage.new(:user_id => self.user_id, :course_id => self.homework_common.course_id, :viewed => false, :status => false) | |||
| end | |||
| end | |||
| def update_score_cache | |||
| if self.user_id != 0 | |||
| CourseCache.update_course_heroes_cache(self.homework_common.course.id,self.user_id,0,{}) | |||
| end | |||
| end | |||
| end | |||
| @@ -199,6 +199,7 @@ class CoursesService | |||
| if params[:type] == 0 | |||
| course_count = CourseCache.course_count_cache(c.id) | |||
| if apply_user.member_of_course?(c) | |||
| #将角色改为老师或者教辅 | |||
| member = c.members.where(:user_id=>apply_user.id).all[0] | |||
| @@ -209,10 +210,16 @@ class CoursesService | |||
| joined.each do |join| | |||
| join.destroy | |||
| end | |||
| #学生数-1 | |||
| CourseCache.update_course_count_cache(c.id,{:student_num=>course_count[:student_num]-1}) | |||
| end | |||
| member.course_group_id = 0 | |||
| member.save | |||
| #教师数+1 | |||
| CourseCache.update_course_count_cache(c.id,{:teacher_num=>course_count[:teacher_num]+1}) | |||
| CourseMessage.create(:user_id => apply_user.id, :course_id => c.id, :viewed => false,:content=> messages.content,:course_message_id=>current_user.id,:course_message_type=>'CourseRequestDealResult',:status=>1) | |||
| messages.update_attributes(:status=>1,:viewed=>1) | |||
| else | |||
| @@ -627,6 +634,9 @@ class CoursesService | |||
| if params[:invite_code].present? | |||
| role_ids = params[:role] | |||
| role_str = role_ids.join(",") | |||
| course_count = CourseCache.course_count_cache(course.id) | |||
| if role_ids.include?("10") && !role_ids.include?("7") && !role_ids.include?("9") | |||
| members = [] | |||
| members << Member.new(:role_ids => [10], :user_id => current_user.id) | |||
| @@ -636,6 +646,8 @@ class CoursesService | |||
| go_coursegroup_flag = 1 if course.course_groups | |||
| course_id = course.id | |||
| send_wechat_join_class_notice current_user,course,10,0 | |||
| #学生数+1 | |||
| CourseCache.update_course_count_cache(course.id,{:student_num=>course_count[:student_num]+1}) | |||
| else | |||
| is_stu = false | |||
| if role_ids.include?("10") | |||
| @@ -647,6 +659,8 @@ class CoursesService | |||
| go_coursegroup_flag = 1 if course.course_groups | |||
| course_id = course.id | |||
| send_wechat_join_class_notice current_user,course,10,0 | |||
| #学生数+1 | |||
| CourseCache.update_course_count_cache(course.id,{:student_num=>course_count[:student_num]+1}) | |||
| end | |||
| #如果已经发送过消息了,那么就要给个提示 | |||
| if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = '#{role_str}' and course_message_id = #{current_user.id} and course_id = #{course.id} and status = 0").count != 0 | |||
| @@ -50,31 +50,42 @@ | |||
| </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 %>"); | |||
| sd_create_editor_from_data(<%= activity[:id]%>, null, "100%", "CourseActivity"); | |||
| }); | |||
| </script> | |||
| <% if activity && activity.course_act %> | |||
| <% act = activity.course_act %> | |||
| <% case activity.course_act_type.to_s %> | |||
| <% when 'HomeworkCommon' %> | |||
| <%= render :partial => 'users/course_homework', :locals => {:activity => act, :user_activity_id => activity.id, :hw_status => 2} %> | |||
| <% when 'News' %> | |||
| <%= render :partial => 'users/course_news', :locals => {:activity => act, :user_activity_id => activity.id} %> | |||
| <% when 'Message' %> | |||
| <%= render :partial => 'users/course_message', :locals => {:activity => act, :user_activity_id => activity.id,:is_course=>1,:is_board=>0} %> | |||
| <% when 'Poll' %> | |||
| <%= render :partial => 'users/course_poll', :locals => {:activity => act, :user_activity_id => activity.id} %> | |||
| <% when 'JournalsForMessage' %> | |||
| <%= render :partial => 'users/course_journalsformessage', :locals => {:activity => act, :user_activity_id => activity.id} %> | |||
| <% when 'Attachment' %> | |||
| <%= render :partial => 'users/course_attachment', :locals => {:activity => act, :user_activity_id => activity.id} %> | |||
| <% when 'Course' %> | |||
| <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => activity.id} %> | |||
| <% end %> | |||
| <% if activity && activity[:course_act_id] %> | |||
| <%# className = activity[:course_act_type].classify.constantize %> | |||
| <%# if activity[:course_act_type] == 'Message' %> | |||
| <%# act = MessagesCache.message_cache(activity[:course_act_id]) %> | |||
| <%# elsif activity[:course_act_type] == 'News' %> | |||
| <%# act = NewsCache.news_cache(activity[:course_act_id]) %> | |||
| <%# elsif activity[:course_act_type] == 'HomeworkCommon' %> | |||
| <%# act = HomeworkCommonCache.homework_common_cache(activity[:course_act_id])%> | |||
| <%# else %> | |||
| <%# act = className.find(activity[:course_act_id]) %> | |||
| <%# end %> | |||
| <% act = get_act_by_cache(activity[:course_act_id],activity[:course_act_type])%> | |||
| <% case activity[:course_act_type] %> | |||
| <% when 'HomeworkCommon' %> | |||
| <%= render :partial => 'users/course_homework', :locals => {:activity => act, :user_activity_id =>activity[:id], :hw_status => 2} %> | |||
| <% when 'News' %> | |||
| <%= render :partial => 'users/course_news', :locals => {:activity => act, :user_activity_id => activity[:id]} %> | |||
| <% when 'Message' %> | |||
| <%= render :partial => 'users/course_message', :locals => {:activity => act, :user_activity_id =>activity[:id],:is_course=>1,:is_board=>0} %> | |||
| <% when 'Poll' %> | |||
| <%= render :partial => 'users/course_poll', :locals => {:activity => act, :user_activity_id => activity[:id]} %> | |||
| <% when 'JournalsForMessage' %> | |||
| <%= render :partial => 'users/course_journalsformessage', :locals => {:activity => act, :user_activity_id=> activity[:id]} %> | |||
| <% when 'Attachment' %> | |||
| <%= render :partial => 'users/course_attachment', :locals => {:activity => act, :user_activity_id =>activity[:id]} %> | |||
| <% when 'Course' %> | |||
| <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => activity[:id]} %> | |||
| <% end %> | |||
| <% end %> | |||
| <% end %> | |||
| <% end %> | |||
| @@ -1,4 +1,4 @@ | |||
| <% unless contributor_course_scor(course.id).count == 0 %> | |||
| <% unless contributor_course_scor_ex(course.id).count == 0 %> | |||
| <div> | |||
| <ul class="rankList"> | |||
| <h3 style="font-size: 14px; font-weight: normal;"> | |||
| @@ -22,43 +22,45 @@ | |||
| 班级留言:留言数 x 1 <br/> | |||
| 总得分为以上得分之和</div> | |||
| </div> | |||
| <% contributor_course_scor(course.id).each do |contributor_score| %> | |||
| <% total_score = contributor_score.con_score %> | |||
| <% if !total_score.nil? && total_score !=0 %> | |||
| <li> | |||
| <%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "50", :height => "50", :class=> "rankPortrait"),user_path(contributor_score.user) %> | |||
| <p><%=link_to contributor_score.user.show_name, user_path(contributor_score.user.id), :title => contributor_score.user.show_name %></p> | |||
| <p><span class="sy_corange" style="cursor:pointer"> | |||
| <% contributor_course_scor_ex(course.id).each do |contributor_score| %> | |||
| <% total_score = contributor_score[:total_score] %> | |||
| <% unless total_score ==0 %> | |||
| <li> | |||
| <%# user = UserCache.user_cache(contributor_score[:user_id]) %> | |||
| <% user = User.find(contributor_score[:user_id])%> | |||
| <%=link_to image_tag(url_to_avatar(user), :width => "50", :height => "50", :class=> "rankPortrait"),user_path(user) %> | |||
| <p><%=link_to user.show_name, user_path(user.id), :title => user.show_name %></p> | |||
| <p><span class="sy_corange" style="cursor:pointer"> | |||
| <a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="sy_corange"> | |||
| <%=total_score %></a></span></p> | |||
| <div style="display: none" class="numIntro"> | |||
| <div class="contributor-course-calculate">积分计算</div> | |||
| <%# unless contributor_score.resource_num.to_i == 0 %> | |||
| <div style="padding-left: 2px;padding-bottom: 2px;padding-right: 2px"> | |||
| 资源发布数 x 5 = <%= contributor_score.resource_num.to_i %> x 5 = <%= contributor_score.resource_num.to_i * 5 %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.message_num.to_i == 0 %> | |||
| 问答发布数 x 2 = <%= contributor_score.message_num.to_i %> x 2 = <%= contributor_score.message_num.to_i * 2 %></br> | |||
| 通知发布数 x 1 = <%= contributor_score.news_num.to_i %> x 1 = <%= contributor_score.news_num.to_i %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.message_reply_num.to_i == 0 %> | |||
| 问答回帖数 x 1 = <%= contributor_score.message_reply_num.to_i %> x 1 = <%= contributor_score.message_reply_num.to_i %></br> | |||
| 作业留言数 x 1 = <%= contributor_score.homework_journal_num.to_i %> x 1 = <%= contributor_score.homework_journal_num.to_i %></br> | |||
| 通知留言数 x 1 = <%= contributor_score.news_reply_num.to_i %> x 1 = <%= contributor_score.news_reply_num.to_i %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.journal_num.to_i == 0 %> | |||
| 班级留言数 x 1 = <%= contributor_score.journal_num.to_i %> x 1 = <%= contributor_score.journal_num.to_i %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.homework_journal_num.to_i == 0 %> | |||
| <%# end %> | |||
| <%# unless contributor_score.news_reply_num.to_i == 0 %> | |||
| <%# end %> | |||
| 总得分:<%=total_score %> | |||
| <div style="display: none" class="numIntro"> | |||
| <div class="contributor-course-calculate">积分计算</div> | |||
| <%# unless contributor_score.resource_num.to_i == 0 %> | |||
| <div style="padding-left: 2px;padding-bottom: 2px;padding-right: 2px"> | |||
| 资源发布数 x 5 = <%= contributor_score[:resource_num].to_i %> x 5 = <%= contributor_score[:resource_num].to_i * 5 %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.message_num.to_i == 0 %> | |||
| 问答发布数 x 2 = <%= contributor_score[:message_num].to_i %> x 2 = <%= contributor_score[:message_num].to_i * 2 %></br> | |||
| 通知发布数 x 1 = <%= contributor_score[:news_num].to_i %> x 1 = <%= contributor_score[:news_num].to_i %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.message_reply_num.to_i == 0 %> | |||
| 问答回帖数 x 1 = <%= contributor_score[:message_reply_num].to_i %> x 1 = <%= contributor_score[:message_reply_num].to_i %></br> | |||
| 作业留言数 x 1 = <%= contributor_score[:homework_journal_num].to_i %> x 1 = <%= contributor_score[:homework_journal_num].to_i %></br> | |||
| 通知留言数 x 1 = <%= contributor_score[:news_reply_num].to_i %> x 1 = <%= contributor_score[:news_reply_num].to_i %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.journal_num.to_i == 0 %> | |||
| 班级留言数 x 1 = <%= contributor_score[:journal_num].to_i %> x 1 = <%= contributor_score[:journal_num].to_i %></br> | |||
| <%# end %> | |||
| <%# unless contributor_score.homework_journal_num.to_i == 0 %> | |||
| <%# end %> | |||
| <%# unless contributor_score.news_reply_num.to_i == 0 %> | |||
| <%# end %> | |||
| 总得分:<%=total_score %> | |||
| </div> | |||
| </div> | |||
| </div> | |||
| </li> | |||
| <% end %> | |||
| <% end %> | |||
| </li> | |||
| <% end %> | |||
| <% end %> | |||
| <div class="cl"></div> | |||
| </ul> | |||
| </div> | |||
| @@ -1,5 +1,6 @@ | |||
| <% hero_homework_scores = hero_homework_score(course, "desc") %> | |||
| <% unless hero_homework_scores.map(&:score).detect{|s| s.to_i != 0}.nil? %> | |||
| <% hero_homework_scores = hero_homework_score_ex(course, "desc") %> | |||
| <%# unless hero_homework_scores.map(&:score).detect{|s| s.to_i != 0}.nil? %> | |||
| <% unless hero_homework_scores.count == 0 %> | |||
| <ul class="rankList"> | |||
| <h4 style="font-size: 14px; font-weight: normal;"> | |||
| <% if (User.current.logged? && course.open_student == 1) || (User.current.member_of_course?(course)) || User.current.admin? %> | |||
| @@ -14,10 +15,12 @@ | |||
| </div> | |||
| </div> | |||
| <% hero_homework_scores.each do |student_score| %> | |||
| <% if student_score.score.to_i != 0 %> | |||
| <li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(student_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(student_score.user) %></a> | |||
| <p><a href="javascript:void:(0);"><%=link_to student_score.user.show_name, user_path(student_score.user), :title => student_score.user.show_name %></a></p> | |||
| <p><span class="c_red" style="cursor:pointer" ><%= student_score.score<0 ? 0 : student_score.score.to_i %></span></p> | |||
| <%# user = UserCache.user_cache(student_score[:user_id]) %> | |||
| <% user = User.find(student_score[:user_id])%> | |||
| <% if student_score[:score].to_i != 0 %> | |||
| <li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(user) %></a> | |||
| <p><a href="javascript:void:(0);"><%=link_to user.show_name, user_path(user), :title => user.show_name %></a></p> | |||
| <p><span class="c_red" style="cursor:pointer" ><%= student_score[:score]<0 ? 0 : student_score[:score].to_i %></span></p> | |||
| </li> | |||
| <% end %> | |||
| <% end %> | |||
| @@ -9,11 +9,13 @@ | |||
| </div> | |||
| <div class="cl"></div> | |||
| <p class="sy_cgrey ml20"> | |||
| <% homework_count = e_course.homework_commons.where("publish_time <= '#{Date.today}'").count %> | |||
| <%# homework_count = e_course.homework_commons.where("publish_time <= '#{Date.today}'").count %> | |||
| <% homework_count = visable_course_homework_ex e_course %> | |||
| <% if homework_count > 0 %> | |||
| 作业<span class="sy_cir_grey ml5 mr5"><%=homework_count %></span> | |||
| <% end %> | |||
| <% file_count = visable_attachemnts_incourse(e_course).count %> | |||
| <%# file_count = visable_attachemnts_incourse(e_course).count %> | |||
| <% file_count = visable_attachemnts_incourse_ex(e_course).count %> | |||
| <% if file_count > 0 %> | |||
| 资源<span class="sy_cir_grey ml5 mr5"><%=file_count %></span> | |||
| <% end %> | |||
| @@ -52,7 +52,8 @@ | |||
| <% else %> | |||
| <% @homework_commons.each_with_index do |homework_common,index |%> | |||
| <li class="pr10"> | |||
| <%= link_to "作业#{@homework_commons.count - index}:#{homework_common.name}",student_work_index_path(:homework => homework_common.id),:target=>"_blank"%> | |||
| <%#= link_to "作业#{@homework_commons.count - index}:#{homework_common.name}",student_work_index_path(:homework => homework_common.id),:target=>"_blank"%> | |||
| <%= link_to "作业#{@homework_commons.count - index}:#{homework_common[:name]}",student_work_index_path(:homework => homework_common[:id]),:target=>"_blank"%> | |||
| </li> | |||
| <% end%> | |||
| <% end %> | |||
| @@ -1,7 +1,13 @@ | |||
| <% 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 %> | |||
| <% count_data = CourseCache.course_count_cache(@course.id) %> | |||
| <% teacher_num = count_data[:teacher_num] %> | |||
| <% student_num = count_data[:student_num] %> | |||
| <% course_file_num = visable_attachemnts_incourse_ex(@course).count %> | |||
| <p class="sy_cgrey mb10 mr20"> | |||
| <%= link_to(@course.teacher.show_name, user_path(@course.teacher), :class => 'sy_cgrey') %> | |||
| > | |||
| @@ -1,4 +1,5 @@ | |||
| <% all_count = @user.favorite_courses.visible.where("is_delete =?", 0).count%> | |||
| <%# all_count = @user.favorite_courses.visible.where("is_delete =?", 0).count%> | |||
| <% all_count = UserCache.user_favorite_courses_cache(@user.id).count%> | |||
| <div id="homepageLeftMenuCourses"> | |||
| <ul class="user_sub_menu" id="user_courses_li"> | |||
| <%= render :partial => 'layouts/user_courses', :locals => {:courses => courses,:user => @user,:all_count => all_count,:page => 0} %> | |||
| @@ -1,4 +1,5 @@ | |||
| <% all_count = @user.favorite_projects.visible.count%> | |||
| <%# all_count = @user.favorite_projects.visible.count%> | |||
| <% all_count = UserCache.user_favorite_projects_cache(@user.id).count%> | |||
| <div id="homepageLeftMenuForge"> | |||
| <ul class="user_sub_menu" id="user_projects_li"> | |||
| <%= render :partial => 'layouts/user_projects', :locals => {:projects => projects,:user => @user, :all_count => all_count, :page => 0} %> | |||
| @@ -1,4 +1,5 @@ | |||
| <% courses.each do |course|%> | |||
| <% course = Course.find(course[:id])%> | |||
| <li class="pr"> | |||
| <span class="user_icons_class"></span> | |||
| <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) %> | |||
| @@ -1,4 +1,5 @@ | |||
| <% projects.each do |project|%> | |||
| <% project = Project.find(project[:id])%> | |||
| <li> | |||
| <span class="user_icons_class"></span> | |||
| <% count = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count %> | |||
| @@ -1,9 +1,13 @@ | |||
| <%# course_model %> | |||
| <%# course_file_num = Attachment.where(:container_type => "Course", :container_id => @course.id).count %> | |||
| <% course_file_num = visable_attachemnts_incourse(@course).count%> | |||
| <%# course_file_num = visable_attachemnts_incourse(@course).count%> | |||
| <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> | |||
| <% homework_num = visable_course_homework @course %> | |||
| <%# homework_num = visable_course_homework @course %> | |||
| <% count_data = CourseCache.course_count_cache(@course.id) %> | |||
| <% course_file_num = visable_attachemnts_incourse_ex(@course).count %> | |||
| <% homework_num = visable_course_homework_ex @course %> | |||
| <!DOCTYPE html> | |||
| <html lang="en" xmlns="http://www.w3.org/1999/html"> | |||
| @@ -59,9 +63,9 @@ | |||
| <div class="sy_class_l fl" id="courseLSide"> | |||
| <div class="sy_class_leftnav mb12"> | |||
| <ul class="accordion"> | |||
| <% unless show_nav?(@course.course_activities.count) %> | |||
| <% unless show_nav?(count_data[:act_count]) %> | |||
| <li id="sy_01" class="sy_icons_index"> | |||
| <a href="<%=course_path(@course) %>" >动态<span><%=@course.course_activities.count %></span></a> | |||
| <a href="<%=course_path(@course) %>" >动态<span><%=count_data[:act_count] %></span></a> | |||
| </li> | |||
| <% end %> | |||
| <% course_board = @course.boards.where("parent_id is NULL").first %> | |||
| @@ -75,15 +79,15 @@ | |||
| <%= render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board} %> | |||
| </div> | |||
| <% end %> | |||
| <% unless show_nav?(@course.homework_commons.count) %> | |||
| <% unless show_nav?(CourseCache.course_homeworks_cache(@course.id).count) %> | |||
| <li id="sy_03" class="sy_icons_hwork"> | |||
| <a href="<%= homework_common_index_path(:course => @course.id) %>">作业<span><%=homework_num %></span></a> | |||
| <%= link_to( "",homework_common_index_path(:course => @course.id,:is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_course_homework_new)}") if is_teacher %> | |||
| </li> | |||
| <% end %> | |||
| <% unless show_nav?(@course.news.count) %> | |||
| <% unless show_nav?(count_data[:news_count]) %> | |||
| <li id="sy_04" class="sy_icons_news"> | |||
| <a href="<%=course_news_index_path(@course) %>">通知<span><%=@course.news.count %></span></a> | |||
| <a href="<%=course_news_index_path(@course) %>">通知<span><%=count_data[:news_count] %></span></a> | |||
| <%= link_to( "",new_course_news_path(@course,:is_new=>1), :class => 'sy_class_add', :title =>"#{l(:label_course_news_new)}") if is_teacher %> | |||
| </li> | |||
| <% end %> | |||
| @@ -164,7 +164,8 @@ | |||
| <li id="user_01" class="user_icons_course"> | |||
| <%= link_to '班级',{:controller => "users", :action => "user_courselist", :id => @user.id}, :id => "user_course_list" %> | |||
| <font class="show-all-sub"><%= link_to '全部',{:controller => "users", :action => "user_courselist", :id => @user.id}, :style => "color:#aaa;" %></font> | |||
| <% courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10) %> | |||
| <%# courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10) %> | |||
| <% courses = get_user_favorite_courses(@user.id,0) %> | |||
| <div class="<%= courses.empty? ? 'none' : ''%>" id="homepage_left_course_list"> | |||
| <%=render :partial => 'layouts/homepage_left_course_list', :locals => {:courses => courses} %> | |||
| </div> | |||
| @@ -192,7 +193,8 @@ | |||
| <li id="user_06" class="user_icons_project"> | |||
| <%= link_to '项目',{:controller => "users", :action => "user_projectlist", :id => @user.id}, :id => 'user_project_list'%> | |||
| <font class="show-all-sub"><%= link_to '全部',{:controller => "users", :action => "user_projectlist", :id => @user.id}, :style => "color:#aaa;" %></font> | |||
| <% projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10)%> | |||
| <%# projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10)%> | |||
| <% projects = get_user_favorite_projects(@user.id,0) %> | |||
| <div class="<%= projects.empty? ? 'none' : ''%>" id="homepage_left_project_list"> | |||
| <%=render :partial => 'layouts/homepage_left_project_list', :locals => {:projects => projects} %> | |||
| </div> | |||
| @@ -1,13 +1,13 @@ | |||
| <% if PraiseTread.praised(activity) %> | |||
| <% num = PraiseCache.praise_cache(activity.id,activity.class)[:praise_num] %> | |||
| <% if !PraiseTread.praised(activity) %> | |||
| <a href='<%= praise_tread_praise_plus_path({:obj_id=>activity.id,:obj_type=>activity.class,:user_activity_id=>user_activity_id,:type=>type }) %>' data-remote="true" class="<%=type == 'reply'? 'fr' : 'ml15' %> likeButton" title="点赞" > | |||
| <span class="likeText">赞</span> | |||
| <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> | |||
| <span class="likeNum"><%= (num.nil? ? 0 : num) > 0 ? "(#{(num.nil? ? 0 : num)})" : "" %></span> | |||
| <span class="likeNum"><%= num > 0 ? "(#{num})" : "" %></span> | |||
| </a> | |||
| <% else %> | |||
| <a href='<%= praise_tread_praise_minus_path({:obj_id=>activity.id,:obj_type=>activity.class,:user_activity_id=>user_activity_id,:type=>type }) %>' data-remote="true" class="<%=type == 'reply'? 'fr' : 'ml15' %> likeButton" title="取消点赞" > | |||
| <span class="likeText">已赞</span> | |||
| <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> | |||
| <span class="likeNum"><%= (num.nil? ? 0 : num) > 0 ? "(#{(num.nil? ? 0 : num)})" : "" %></span> | |||
| <span class="likeNum"><%= num > 0 ? "(#{num})" : "" %></span> | |||
| </a> | |||
| <% end %> | |||
| <% end %> | |||
| @@ -82,7 +82,8 @@ | |||
| <div class="cl"></div> | |||
| </div> | |||
| <% all_comments = []%> | |||
| <% all_replies = get_all_children(all_comments, activity) %> | |||
| <%# all_replies = get_all_children(all_comments, activity) %> | |||
| <% all_replies = ReplyCache.message_replys_cache(activity.id) %> | |||
| <% count = all_replies.count %> | |||
| <%# allow_delete = (activity.user == User.current || User.current.admin? || User.current.allowed_to?(:as_teacher,activity.course)) %> | |||
| <%# count = fetch_user_leaveWord_reply(activity).count %> | |||
| @@ -30,24 +30,35 @@ | |||
| <% forge_acts.each do |activity| -%> | |||
| <script> | |||
| $(function () { | |||
| sd_create_editor_from_data(<%= activity.id %>, null, "100%", "<%= activity.class.to_s %>"); | |||
| sd_create_editor_from_data(<%= activity['id'] %>, null, "100%", "ForgeActivity"); | |||
| }); | |||
| </script> | |||
| <!--创建--> | |||
| <% case activity.forge_act_type %> | |||
| <%# className = activity['forge_act_type'].classify.constantize %> | |||
| <%# if activity['forge_act_type'] == 'Message' %> | |||
| <%# act = MessagesCache.message_cache(activity['forge_act_id']) %> | |||
| <%# elsif activity['forge_act_type'] == 'News' %> | |||
| <%# act = NewsCache.news_cache(activity['forge_act_id']) %> | |||
| <%# elsif activity['forge_act_type'] == 'Issue' %> | |||
| <%# act = IssueCache.issue_cache(activity['forge_act_id']) %> | |||
| <%# else %> | |||
| <%# act = className.find(activity['forge_act_id']) rescue nil %> | |||
| <%# end %> | |||
| <% act = get_act_by_cache(activity['forge_act_id'],activity['forge_act_type'])%> | |||
| <% case activity['forge_act_type'] %> | |||
| <% when "Project" %> | |||
| <%= render :partial => 'projects/project_create', :locals => {:activity => activity, :user_activity_id => activity.id} %> | |||
| <%= render :partial => 'projects/project_create', :locals => {:activity => {:project_id=>@project.id}, :user_activity_id => activity['id']} %> | |||
| <!--缺陷动态--> | |||
| <% when "Issue" %> | |||
| <%= render :partial => 'projects/act_issues', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %> | |||
| <%= render :partial => 'projects/act_issues', :locals => {:activity => act, :user_activity_id => activity['id'], :project_id => @project.id} %> | |||
| <!--message --> | |||
| <% when "Message" %> | |||
| <%= render :partial => 'projects/act_messages', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :is_course => 1, :is_board => 0} %> | |||
| <%= render :partial => 'projects/act_messages', :locals => {:activity => act, :user_activity_id => activity['id'], :is_course => 1, :is_board => 0} %> | |||
| <!--Attachment --> | |||
| <% when "Attachment" %> | |||
| <%= render :partial => 'projects/project_attachment', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id } %> | |||
| <%= render :partial => 'projects/project_attachment', :locals => {:activity => act, :user_activity_id => activity['id'] } %> | |||
| <% when "Commit" %> | |||
| <%= render :partial => 'projects/project_commit', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :identifier => get_rep_identifier_by_project(@project) } %> | |||
| <%= render :partial => 'projects/project_commit', :locals => {:activity => act, :user_activity_id => activity['id'], :identifier => get_rep_identifier_by_project(@project) } %> | |||
| <% end %> | |||
| <% end %> | |||
| <% end %> | |||
| @@ -1,4 +1,4 @@ | |||
| <% project = Project.find(activity.project_id) %> | |||
| <% project = Project.find(activity[:project_id]) %> | |||
| <% user = User.find(project.user_id)%> | |||
| <div class="container-big mt10"> | |||
| <div class="pr"> | |||
| @@ -4,7 +4,8 @@ | |||
| </div> | |||
| <% if !comment.parent.nil? && !comment.parent.parent.nil? %> | |||
| <% parents_rely = [] %> | |||
| <% parents_rely = get_reply_parents_no_root parents_rely, comment %> | |||
| <%# parents_rely = get_reply_parents_no_root parents_rely, comment %> | |||
| <% parents_rely = get_reply_parents_no_root_ex(parents_rely, comment,comment.class.to_s) %> | |||
| <% length = parents_rely.length %> | |||
| <div id="comment_reply_<%=comment.id %>"> | |||
| <% if length <= 2 %> | |||
| @@ -12,14 +13,31 @@ | |||
| <% else %> | |||
| <div class="orig_cont clearfix"> | |||
| <div class="orig_cont clearfix"> | |||
| <%=render :partial => 'projects/comment_reply_detail', :locals => {:comment => parents_rely[length - 1]} %> | |||
| <div> | |||
| <%#=render :partial => 'projects/journal_comment_reply', :locals => {:comment => parents_rely[length - 1]} %> | |||
| <% if comment.class.to_s == 'Message' %> | |||
| <%=render :partial => 'projects/journal_comment_reply', :locals => {:comment => Message.find(parents_rely[length - 1][:id])} %> | |||
| <% else %> | |||
| <%=render :partial => 'projects/journal_comment_reply', :locals => {:comment => parents_rely[length - 1]} %> | |||
| <% end %> | |||
| </div> | |||
| <%#=render :partial => 'projects/comment_reply_detail', :locals => {:comment => parents_rely[length - 2]} %> | |||
| <% if comment.class.to_s == 'Message' %> | |||
| <%=render :partial => 'projects/comment_reply_detail', :locals => {:comment => Message.find(parents_rely[length - 2][:id])} %> | |||
| <% else %> | |||
| <%=render :partial => 'projects/comment_reply_detail', :locals => {:comment => parents_rely[length - 2]} %> | |||
| <% end %> | |||
| </div> | |||
| <div class="orig_cont_hide_issue clearfix"> | |||
| <span class="orig_icon" >↓ </span> | |||
| <span class="orig_icon" style="display:none;" > ↑</span><span class="">已经隐藏<%=(length - 2).to_s %>个楼层</span> | |||
| <%= link_to '[点击展开]', show_all_replies_users_path(:comment => comment, :type => comment.class), :remote=>true, :class => 'linkBlue2' %> | |||
| </div> | |||
| <%=render :partial => 'projects/comment_reply_detail', :locals => {:comment => parents_rely[0]} %> | |||
| <% if comment.class.to_s == 'Message' %> | |||
| <%=render :partial => 'projects/comment_reply_detail', :locals => {:comment => Message.find(parents_rely[0][:id])} %> | |||
| <% else %> | |||
| <%=render :partial => 'projects/comment_reply_detail', :locals => {:comment => parents_rely[0]} %> | |||
| <% end %> | |||
| </div> | |||
| <% end %> | |||
| </div> | |||
| @@ -1,5 +1,8 @@ | |||
| <ul> | |||
| <% comments.each do |comment| %> | |||
| <% if type == 'Message' %> | |||
| <% comment = MessagesCache.message_cache(comment[:id]) #Message.find(comment[:id]) %> | |||
| <% end %> | |||
| <script type="text/javascript"> | |||
| $(function(){ | |||
| showNormalImage('reply_content_<%= comment.id %>'); | |||
| @@ -32,7 +32,11 @@ | |||
| <span class="c_red">系统提示:该作业要求各组长提交作品,提交作品时请添加组成员。谢谢配合!</span> | |||
| <% end %> | |||
| <div class="homepagePostSubmitContainer"> | |||
| <% tStarttime = Time.now %> | |||
| <%= render :partial => 'users/homework_opr', :locals => {:activity => activity, :is_teacher => is_teacher, :hw_status => hw_status, :user_activity_id => user_activity_id} %> | |||
| <% tEndtime = Time.now | |||
| tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 | |||
| logger.info "homework_opr user wait time = #{tUsedtime} 毫秒" %> | |||
| <% if activity.homework_detail_manual && activity.homework_detail_manual.comment_status < 2 %> | |||
| <div class="homepagePostDeadline">提交截止时间:<%= activity.end_time.to_s %> 23:59</div> | |||
| <% elsif activity.homework_detail_manual && activity.homework_detail_manual.comment_status >= 2 && activity.anonymous_comment == 0%> | |||
| @@ -44,7 +48,11 @@ | |||
| </div> | |||
| <% end %> | |||
| </div> | |||
| <% tStarttime = Time.now %> | |||
| <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> | |||
| <% tEndtime = Time.now | |||
| tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 | |||
| logger.info "intro_content user wait time = #{tUsedtime} 毫秒" %> | |||
| <div class="cl"></div> | |||
| <div id="intro_content_show_<%= user_activity_id%>" class="fr" style="display:none;"><a href="javascript:void(0);" class="linkBlue">[展开]</a></div> | |||
| @@ -54,10 +62,18 @@ | |||
| <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> | |||
| </div> | |||
| <% tStarttime = Time.now %> | |||
| <%= render :partial => "users/homework_base_info", :locals =>{:activity => activity, :user_activity_id =>user_activity_id, :is_teacher => is_teacher, :hw_status => hw_status} %> | |||
| </div> | |||
| <% tEndtime = Time.now | |||
| tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 | |||
| logger.info "homework_base_info user wait time = #{tUsedtime} 毫秒" %> | |||
| </div> | |||
| <div class="cl"></div> | |||
| </div> | |||
| <% tStarttime = Time.now %> | |||
| <%= render :partial => 'users/homework_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id, :hw_status => hw_status, :is_teacher => is_teacher} %> | |||
| <% tEndtime = Time.now | |||
| tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 | |||
| logger.info "homework_post_reply user wait time = #{tUsedtime} 毫秒" %> | |||
| </div> | |||
| @@ -38,8 +38,9 @@ | |||
| </div> | |||
| <div class="cl"></div> | |||
| </div> | |||
| <% all_comments = []%> | |||
| <% all_replies = JournalsForMessage.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <%# all_comments = []%> | |||
| <% all_replies = ReplyCache.leave_replys_cache(activity.id) %> | |||
| <%# all_replies = JournalsForMessage.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <% count = all_replies.count %> | |||
| <div class="homepagePostReply"> | |||
| <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id} %> | |||
| @@ -2,7 +2,7 @@ | |||
| <div class="homepagePostBrief"> | |||
| <div class="homepagePostPortrait"> | |||
| <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author, :host => Setting.host_user), :alt => "用户头像" %> | |||
| <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> | |||
| <%#= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> | |||
| </div> | |||
| <div class="homepagePostDes"> | |||
| <div class="homepagePostTo break_word"> | |||
| @@ -78,9 +78,11 @@ | |||
| </div> | |||
| <div class="cl"></div> | |||
| </div> | |||
| <% all_comments = []%> | |||
| <%# all_replies = get_all_children(all_comments, activity) %> | |||
| <% all_replies = Message.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <%# all_replies = Message.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <% all_replies = ReplyCache.message_replys_cache(activity.id) %> | |||
| <% count = all_replies.count %> | |||
| <div class="homepagePostReply"> | |||
| <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id,:is_course => is_course,:is_board =>is_board} %> | |||
| @@ -62,12 +62,13 @@ | |||
| </div> | |||
| <div class="cl"></div> | |||
| </div> | |||
| <% count=activity.comments.count %> | |||
| <% all_comments = ReplyCache.news_replys_cache(activity.id)%> | |||
| <%# count=activity.comments.count %> | |||
| <% count=all_comments.count %> | |||
| <div class="homepagePostReply"> | |||
| <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id} %> | |||
| <% comments = activity.comments.reorder("created_on desc").limit(3) %> | |||
| <% comments = all_comments[0..2] %> | |||
| <%# comments = activity.comments.reorder("created_on desc").limit(3) %> | |||
| <% if count > 0 %> | |||
| <div class="" id="reply_div_<%= user_activity_id %>"> | |||
| <%= render :partial => 'users/news_replies', :locals => {:comments => comments, :user_activity_id => user_activity_id, :type => 'News', :activity_id => activity.id} %> | |||
| @@ -1,8 +1,10 @@ | |||
| <% count=activity.journals_for_messages.count %> | |||
| <% all_replys = ReplyCache.homework_replys_cache(activity.id) %> | |||
| <%# count=activity.journals_for_messages.count %> | |||
| <% count=all_replys.count %> | |||
| <div class="homepagePostReply" id="homework_post_reply_<%= user_activity_id %>"> | |||
| <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id, :hw_status => hw_status} %> | |||
| <% comments = activity.journals_for_messages.reorder("created_on desc").limit(3) %> | |||
| <%# comments = activity.journals_for_messages.reorder("created_on desc").limit(3) %> | |||
| <% comments = all_replys[0..2]%> | |||
| <% if count > 0 %> | |||
| <div class="" id="reply_div_<%= user_activity_id %>"> | |||
| <%=render :partial => 'users/news_replies', :locals => {:comments => comments, :type => 'HomeworkCommon', :hw_status => hw_status, :is_teacher => is_teacher, :user_activity_id => user_activity_id, :activity_id => activity.id} %> | |||
| @@ -4,7 +4,8 @@ | |||
| </div> | |||
| <% if !comment.parent.nil? && !comment.parent.parent.nil? %> | |||
| <% parents_rely = [] %> | |||
| <% parents_rely = get_reply_parents_no_root parents_rely, comment %> | |||
| <% parents_rely = get_reply_parents_no_root_ex(parents_rely, comment,comment.class.to_s) %> | |||
| <%# parents_rely = ReplyCache.get_message_reply_parents_cache(comment.root_id,comment.id) %> | |||
| <% length = parents_rely.length %> | |||
| <div id="comment_reply_<%=comment.id %>"> | |||
| <% if length <= 2 %> | |||
| @@ -12,17 +13,26 @@ | |||
| <% else %> | |||
| <div class="orig_cont clearfix"> | |||
| <div class="orig_cont clearfix"> | |||
| <!--<div>--> | |||
| <!--<%#=render :partial => 'users/journal_comment_reply', :locals => {:comment => parents_rely[length - 1]} %>--> | |||
| <!--</div>--> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[length - 1]} %> | |||
| <% case comment.class.to_s %> | |||
| <% when 'Message','JournalsForMessage','BlogComment' %> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment =>get_act_by_cache(parents_rely[length - 1][:id],comment.class.to_s)}%> | |||
| <% else %> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[length - 1]} %> | |||
| <% end %> | |||
| </div> | |||
| <div class="orig_cont_hide clearfix"> | |||
| <span class="orig_icon" >↓ </span> | |||
| <span class="orig_icon" style="display:none;" > ↑</span><span class="">已经隐藏<%=(length - 2).to_s %>个楼层</span> | |||
| <%= link_to '[点击展开]', show_all_replies_users_path(:comment => comment, :type => comment.class),:remote=>true, :class => 'linkBlue2' %> | |||
| </div> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[0]} %> | |||
| <%#=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[0]} %> | |||
| <% case comment.class.to_s %> | |||
| <% when 'Message','JournalsForMessage','BlogComment' %> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment =>get_act_by_cache(parents_rely[0][:id],comment.class.to_s)}%> | |||
| <% else %> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[0]} %> | |||
| <% end %> | |||
| </div> | |||
| <% end %> | |||
| </div> | |||
| @@ -1,5 +1,13 @@ | |||
| <ul> | |||
| <% comments.each do |comment| %> | |||
| <%# if type == 'Message' %> | |||
| <%# comment = MessagesCache.message_cache(comment[:id]) #Message.find(comment[:id]) %> | |||
| <%# elsif type == 'JournalsForMessage'%> | |||
| <%# comment = JournalsForMessage.find(comment[:id]) %> | |||
| <%# elsif type == 'BlogComment'%> | |||
| <%# comment = BlogComment.find(comment[:id]) %> | |||
| <%# end %> | |||
| <% comment = get_act_by_cache(comment[:id],type) %> | |||
| <script type="text/javascript"> | |||
| $(function(){ | |||
| showNormalImage('reply_content_<%= comment.id %>'); | |||
| @@ -24,7 +32,9 @@ | |||
| <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> | |||
| </span> | |||
| <% if type == 'Message' %> | |||
| <% topic = comment.root %> | |||
| <%# topic = comment.root %> | |||
| <% topic = MessagesCache.message_cache(comment.root_id) if topic == nil %> | |||
| <%# topic = Message.find(comment.root_id) if topic == nil %> | |||
| <% if !topic.locked? && authorize_for('messages', 'reply') %> | |||
| <span style="position: relative" class="fr mr20"> | |||
| <%= link_to( | |||
| @@ -4,7 +4,7 @@ | |||
| </div> | |||
| <% if !comment.parent.nil? %> | |||
| <% parents_rely = [] %> | |||
| <% parents_rely = get_reply_parents parents_rely, comment %> | |||
| <% parents_rely = get_reply_parents_ex parents_rely, comment,comment.class.to_s %> | |||
| <% length = parents_rely.length %> | |||
| <div id="comment_reply_<%=comment.id %>"> | |||
| <% if length <= 2 %> | |||
| @@ -12,17 +12,24 @@ | |||
| <% else %> | |||
| <div class="orig_cont clearfix"> | |||
| <div class="orig_cont clearfix"> | |||
| <!--<div>--> | |||
| <!--<%#=render :partial => 'users/comment_reply', :locals => {:comment => parents_rely[length - 1]} %>--> | |||
| <!--</div>--> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[length - 1]} %> | |||
| <% case comment.class.to_s %> | |||
| <% when 'Comment','JournalsForMessage'%> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment =>get_act_by_cache(parents_rely[length - 1][:id],comment.class.to_s)}%> | |||
| <% else %> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[length - 1]} %> | |||
| <% end %> | |||
| </div> | |||
| <div class="orig_cont_hide clearfix"> | |||
| <span class="orig_icon" >↓ </span> | |||
| <span class="orig_icon" style="display:none;" > ↑</span><span class="">已经隐藏<%=(length - 2).to_s %>个楼层</span> | |||
| <%= link_to '[点击展开]', show_all_replies_users_path(:comment => comment, :type => comment.class), :remote=>true, :class => 'linkBlue2' %> | |||
| <%= link_to '[点击展开]', show_all_replies_users_path(:comment => comment, :type => comment.class),:remote=>true, :class => 'linkBlue2' %> | |||
| </div> | |||
| <% case comment.class.to_s %> | |||
| <% when 'Comment','JournalsForMessage'%> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment =>get_act_by_cache(parents_rely[0][:id],comment.class.to_s)}%> | |||
| <% else %> | |||
| <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[0]} %> | |||
| <% end %> | |||
| </div> | |||
| <% end %> | |||
| </div> | |||
| @@ -1,5 +1,10 @@ | |||
| <ul> | |||
| <% comments.each do |comment| %> | |||
| <% if type == 'News' %> | |||
| <% comment = get_act_by_cache(comment[:id],'Comment')#Comment.find(comment[:id]) %> | |||
| <% elsif type == 'HomeworkCommon' %> | |||
| <% comment = get_act_by_cache(comment[:id],'JournalsForMessage') #JournalsForMessage.find(comment[:id]) %> | |||
| <% end %> | |||
| <script type="text/javascript"> | |||
| $(function(){ | |||
| showNormalImage('reply_content_<%= comment.id %>'); | |||
| @@ -56,7 +61,7 @@ | |||
| :title => l(:button_reply)) %> | |||
| <span id="reply_iconup_<%= comment.id %>" class="reply_iconup02" style="display: none"> ︿</span> | |||
| </span> | |||
| <% news = News.find(activity_id) %> | |||
| <% news = get_act_by_cache(activity_id,'News')#News.find(activity_id) %> | |||
| <%= link_to('删除', {:controller => 'comments', :action => 'destroy', :id => activity_id, :comment_id => comment, :user_activity_id => user_activity_id}, | |||
| :id => "delete_reply_#{activity_id}_#{comment.id}",:remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "fr mr20 undis", :title => l(:button_delete)) if (User.current.allowed_to?(:manage_news, news.course) || User.current.allowed_to?(:manage_news, news.project)) %> | |||
| <% elsif type == 'Issue' %> | |||
| @@ -81,8 +81,9 @@ | |||
| </div> | |||
| <div class="cl"></div> | |||
| </div> | |||
| <% all_comments = []%> | |||
| <% all_replies = Message.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <%# all_comments = []%> | |||
| <%# all_replies = Message.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <% all_replies = ReplyCache.message_replys_cache(activity.id) %> | |||
| <% count = all_replies.count %> | |||
| <%# allow_delete = (activity.user == User.current || User.current.admin? || User.current.allowed_to?(:as_teacher,activity.course)) %> | |||
| <%# count = fetch_user_leaveWord_reply(activity).count %> | |||
| @@ -42,7 +42,8 @@ | |||
| <div class="cl"></div> | |||
| </div> | |||
| <%# all_comments = []%> | |||
| <% all_replies = BlogComment.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <%# all_replies = BlogComment.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <% all_replies = ReplyCache.blog_replys_cache(activity.id) %> | |||
| <% count = all_replies.count %> | |||
| <div class="homepagePostReply"> | |||
| <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id, :homepage => 0} %> | |||
| @@ -62,8 +62,9 @@ | |||
| </div> | |||
| <div class="cl"></div> | |||
| </div> | |||
| <% all_comments = []%> | |||
| <% all_replies = JournalsForMessage.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <%# all_comments = []%> | |||
| <%# all_replies = JournalsForMessage.where("root_id = #{activity.id}").reorder("created_on desc") %> | |||
| <% all_replies = ReplyCache.leave_replys_cache(activity.id) %> | |||
| <% count = all_replies.count %> | |||
| <div class="homepagePostReply"> | |||
| <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id} %> | |||
| @@ -12,7 +12,8 @@ RedmineApp::Application.configure do | |||
| # Show full error reports and disable caching | |||
| config.consider_all_requests_local = 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://127.0.0.1:6379/0/cache'#, { expires_in: 90.minutes } | |||
| #config.cache_store = :dalli_store | |||
| # Don't care if the mailer can't send | |||
| config.action_mailer.raise_delivery_errors = true | |||
| @@ -0,0 +1,38 @@ | |||
| # Settings specified here will take precedence over those in config/application.rb | |||
| RedmineApp::Application.configure do | |||
| # The production environment is meant for finished, "live" apps. | |||
| # Code is not reloaded between requests | |||
| config.cache_classes = true | |||
| ##### | |||
| # Customize the default logger (http://ruby-doc.org/core/classes/Logger.html) | |||
| # | |||
| # Use a different logger for distributed setups | |||
| # config.logger = SyslogLogger.new | |||
| # | |||
| # Rotate logs bigger than 1MB, keeps no more than 7 rotated logs around. | |||
| # When setting a new Logger, make sure to set it's log level too. | |||
| # | |||
| # config.logger = Logger.new(config.log_path, 7, 1048576) | |||
| # config.logger.level = Logger::INFO | |||
| # Full error reports are disabled and caching is turned on | |||
| # config.logger = Logger.new('log/production.log', 'daily',1048576) # daily, weekly or monthly | |||
| config.action_controller.perform_caching = true | |||
| # to additional_environment.rb | |||
| # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" | |||
| # config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 90.minutes } | |||
| # | |||
| config.cache_store = :redis_store, 'redis://10.9.52.157:6379/0/cache'#, { expires_in: 90.minutes } | |||
| # Enable serving of images, stylesheets, and javascripts from an asset server | |||
| # config.action_controller.asset_host = "http://assets.example.com" | |||
| # Disable delivery errors if you bad email addresses should just be ignored | |||
| config.action_mailer.raise_delivery_errors = false | |||
| # No email in production log | |||
| config.action_mailer.logger = nil | |||
| config.active_support.deprecation = :log | |||
| end | |||
| @@ -0,0 +1,38 @@ | |||
| # Settings specified here will take precedence over those in config/application.rb | |||
| RedmineApp::Application.configure do | |||
| # The production environment is meant for finished, "live" apps. | |||
| # Code is not reloaded between requests | |||
| config.cache_classes = true | |||
| ##### | |||
| # Customize the default logger (http://ruby-doc.org/core/classes/Logger.html) | |||
| # | |||
| # Use a different logger for distributed setups | |||
| # config.logger = SyslogLogger.new | |||
| # | |||
| # Rotate logs bigger than 1MB, keeps no more than 7 rotated logs around. | |||
| # When setting a new Logger, make sure to set it's log level too. | |||
| # | |||
| # config.logger = Logger.new(config.log_path, 7, 1048576) | |||
| # config.logger.level = Logger::INFO | |||
| # Full error reports are disabled and caching is turned on | |||
| # config.logger = Logger.new('log/production.log', 'daily',1048576) # daily, weekly or monthly | |||
| config.action_controller.perform_caching = true | |||
| # to additional_environment.rb | |||
| # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" | |||
| # config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 90.minutes } | |||
| # | |||
| config.cache_store = :redis_store, 'redis://192.168.80.11:6379/0/cache'#, { expires_in: 90.minutes } | |||
| # Enable serving of images, stylesheets, and javascripts from an asset server | |||
| # config.action_controller.asset_host = "http://assets.example.com" | |||
| # Disable delivery errors if you bad email addresses should just be ignored | |||
| config.action_mailer.raise_delivery_errors = false | |||
| # No email in production log | |||
| config.action_mailer.logger = nil | |||
| config.active_support.deprecation = :log | |||
| end | |||