| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
5397707990 |
Merge branch 'dev_cache' into 'dev_cache'
Redis 缓存课程动态优化 See merge request !58 |
10 years ago |
|
|
5dc27a7acc | redis缓存优化(课程动态500问题,初次查询性能优化) | 10 years ago |
|
|
c88d214bb9 |
处理冲突
Merge branch 'develop' of https://git.trustie.net/jacknudt/trustieforge into dev_cache Conflicts: app/views/courses/_course_activity.html.erb app/views/courses/_course_heroes.html.erb app/views/users/_message_contents.html.erb |
10 years ago |
|
|
6fccc7b50c |
Merge branch 'develop' into dev_cache
Conflicts: .gitignore app/controllers/blogs_controller.rb app/controllers/users_controller.rb app/helpers/application_helper.rb app/models/comment.rb app/models/journals_for_message.rb app/models/news.rb app/views/courses/_course_activity_users.html.erb app/views/layouts/new_base_user.html.erb app/views/projects/_act_messages.html.erb app/views/projects/_project_message_contents.html.erb app/views/users/_course_homework.html.erb app/views/users/_course_journalsformessage.html.erb app/views/users/_course_message.html.erb app/views/users/_course_news.html.erb app/views/users/_homework_post_reply.html.erb app/views/users/_message_contents.html.erb app/views/users/_news_contents.html.erb app/views/users/_project_message.html.erb app/views/users/_user_blog.html.erb app/views/users/_user_journalsformessage.html.erb |
10 years ago |
|
|
2d5fbdfaaa |
Merge branch 'develop' into yuanke_objectcache
Conflicts: app/views/projects/_project_message_contents.html.erb |
10 years ago |
|
|
f4b6cab0d5 | 项目动态更新缓存修改 | 10 years ago |
|
|
0efd386475 | 修改删除班级、项目时缓存的BUG | 10 years ago |
|
|
cb618753f2 | 博客排序修改 | 10 years ago |
|
|
b3ebc34176 | 缓存客删除的BUG | 10 years ago |
|
|
be5ba0a9de | 项目动态删除BUG | 10 years ago |
|
|
d067771679 | 数据库对象缓存都设定个过期时间 | 10 years ago |
|
|
e7afd5dc5c | 缓存对象的出错处理 | 10 years ago |
|
|
c78734c50c | 修改分组作业合成成员BUG | 10 years ago |
|
|
9a15c2b642 | 缓存更新时避免出错 加个出错处理 | 10 years ago |
|
|
6ba203b224 | 修改BUG | 10 years ago |
|
|
abd5ed122b | 活跃度更新缓存时,只有学生才更新 | 10 years ago |
|
|
ee854f7572 | 缓存项目动态显示BUG修复 | 10 years ago |
|
|
5a20297708 | 缓存项目动态的BUG | 10 years ago |
|
|
3a6ed939dd | 修复班级成员角色切换引起的教师数不对的BUG | 10 years ago |
|
|
5908f243bc | Merge branch 'develop' into yuanke_objectcache | 10 years ago |
|
|
bab2969a7e | 忽略oneapm.yml | 10 years ago |
|
|
b40da0437c | 缓存修改 | 10 years ago |
|
|
8588f8b818 | 合并代码漏掉了一段 | 10 years ago |
|
|
1a45428189 | 缓存活跃度\英雄榜都改为6个 | 10 years ago |
|
|
cec157944b |
Merge branch 'develop' into yuanke_objectcache
Conflicts: app/models/homework_common.rb app/views/courses/_course_activity_users.html.erb app/views/users/_course_message.html.erb |
10 years ago |
|
|
e00b174a07 | . | 10 years ago |
|
|
bdfd313e97 | . | 10 years ago |
|
|
e9cccaa4f0 | 对几个回复对象加缓存 | 10 years ago |
|
|
f44634a254 | Merge branch 'yuanke_objectcache' of https://git.trustie.net/jacknudt/trustieforge into yuanke_objectcache | 10 years ago |
|
|
b6642e9856 | 缓存的多级回复显示 | 10 years ago |
|
|
adf0d49c3f | 缓存班级活跃度BUG修改 | 10 years ago |
|
|
57c3610de8 | Merge branch 'yuanke_objectcache' of https://git.trustie.net/jacknudt/trustieforge into yuanke_objectcache | 10 years ago |
|
|
ff179555fb | 修改几个BUG | 10 years ago |
|
|
aa0bfa2188 | Merge branch 'yuanke_objectcache' of https://git.trustie.net/jacknudt/trustieforge into yuanke_objectcache | 10 years ago |
|
|
6c21571ecd | 作业动态加时间打印 | 10 years ago |
|
|
8e98ac2700 | Merge branch 'yuanke_objectcache' of https://git.trustie.net/jacknudt/trustieforge into yuanke_objectcache | 10 years ago |
|
|
895cb77323 | 缓存修改 | 10 years ago |
|
|
b9498df568 | Merge branch 'cxt_course' into yuanke_objectcache | 10 years ago |
|
|
a102bb531f | 挂起作业 | 10 years ago |
|
|
bc0af58e6d | 项目动态缓存 | 10 years ago |
|
|
c1305c9ded | merge | 10 years ago |
|
|
7debb74164 |
Merge branch 'develop' into yuanke_objectcache
Conflicts: app/models/news.rb app/views/users/_message_contents.html.erb app/views/users/_news_contents.html.erb |
10 years ago |
|
|
b183038fbf | 讨论区 和通知 加上缓存 | 10 years ago |
|
|
f024ac6665 | 缓存修改 | 10 years ago |
|
|
e35379641b | .通知 讨论区动态修改 | 10 years ago |
|
|
bd324315c6 | 优化 | 10 years ago |
|
|
0192f27053 | .通知动态缓存修改 | 10 years ago |
|
|
5a309e8c76 | 讨论区动态缓存 | 10 years ago |
|
|
c9a0561694 | 作业列表加缓存 | 10 years ago |
|
|
b84c9cb55d | 班级资源、作业缓存更新 | 10 years ago |
|
|
fa978701f8 | 作业列表缓存 | 10 years ago |
|
|
cc6098a629 | 班级推荐缓存修改 | 10 years ago |
|
|
3d9ec521d8 | 英雄榜缓存修改 | 10 years ago |
|
|
2a6713db4e | 班级收藏、项目收藏、班级动态时间、项目动态时间增加 | 10 years ago |
|
|
d65c0446c3 | date数据比较不用转to_i | 10 years ago |
|
|
2c912eac5b | 对象缓存增加 | 10 years ago |
|
|
da81c56899 | 教师、学生数缓存更新 | 10 years ago |
|
|
9186f48cb4 | . | 10 years ago |
|
|
61c62ac183 | 回复缓存 | 10 years ago |
|
|
e2600eb493 | 赞相关缓存 | 10 years ago |
|
|
8b21f767d6 | 赞数缓存优化 | 10 years ago |
|
|
0ad75ac6b1 | 赞缓存 | 10 years ago |
|
|
7f1863c3d0 | 班级相关缓存 | 10 years ago |
|
|
7c151dec58 | . | 10 years ago |
|
|
39de5edcaa | . | 10 years ago |
|
|
ab77846fe1 | . | 10 years ago |
|
|
db5254a974 | . | 10 years ago |
|
|
d33afa065f | 缓存配置 | 10 years ago |
| @@ -39,4 +39,5 @@ public/javascripts/wechat/node_modules/ | |||||
| .access_token | .access_token | ||||
| tmux*.log | tmux*.log | ||||
| config/wechat.yml | config/wechat.yml | ||||
| config/environments/production.rb | |||||
| config/oneapm.yml | 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 = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first | ||||
| ptc.praise_minus(1) if !ptc.blank? | ptc.praise_minus(1) if !ptc.blank? | ||||
| if ptc.praise_num == 0 | if ptc.praise_num == 0 | ||||
| ptc.delete | |||||
| ptc.destroy | |||||
| end | end | ||||
| obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first | obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first | ||||
| num = !obj.blank? ? get_activity_praise_num(obj) : 0 | 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,535 @@ | |||||
| #班级相关的缓存 | |||||
| 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) | |||||
| data = course.course_activities | |||||
| # course.course_activities.each do |act| | |||||
| # data << { | |||||
| # :id=>act.id, | |||||
| # :user_id=>act.user_id, | |||||
| # :course_act_id=>act.course_act_id, | |||||
| # :course_act_type=>act.course_act_type, | |||||
| # :updated_at=>act.updated_at | |||||
| # } | |||||
| # end | |||||
| Rails.cache.write(key,data) | |||||
| end | |||||
| 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 | |||||
| @@ -310,8 +310,10 @@ class AdminController < ApplicationController | |||||
| if @course.is_excellent == 1 || @course.excellent_option == 1 | if @course.is_excellent == 1 || @course.excellent_option == 1 | ||||
| @course.update_column('is_excellent', 0) | @course.update_column('is_excellent', 0) | ||||
| @course.update_column('excellent_option', 0) | @course.update_column('excellent_option', 0) | ||||
| CourseCache.update_excelletn_courses_cache(@course.id,2,{}) | |||||
| else | else | ||||
| @course.update_column('is_excellent', 1) | @course.update_column('is_excellent', 1) | ||||
| CourseCache.update_excelletn_courses_cache(@course.id,1,{}) | |||||
| end | end | ||||
| respond_to do |format| | respond_to do |format| | ||||
| format.js | format.js | ||||
| @@ -326,6 +328,7 @@ class AdminController < ApplicationController | |||||
| if @course.is_excellent == 1 || @course.excellent_option == 1 | if @course.is_excellent == 1 || @course.excellent_option == 1 | ||||
| @course.update_column('is_excellent', 0) | @course.update_column('is_excellent', 0) | ||||
| @course.update_column('excellent_option', 0) | @course.update_column('excellent_option', 0) | ||||
| CourseCache.update_excelletn_courses_cache(@course.id,2,{}) | |||||
| end | end | ||||
| end | end | ||||
| respond_to do |format| | respond_to do |format| | ||||
| @@ -26,7 +26,8 @@ class BlogsController < ApplicationController | |||||
| @type = 2 | @type = 2 | ||||
| @topics.each do |topic| | @topics.each do |topic| | ||||
| topic[:infocount] = get_praise_num(topic) + BlogComment.where("root_id = #{topic.id}").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 | if topic[:infocount] < 0 | ||||
| topic[:infocount] = 0 | topic[:infocount] = 0 | ||||
| end | end | ||||
| @@ -643,8 +643,16 @@ class CoursesController < ApplicationController | |||||
| def private_or_public | def private_or_public | ||||
| if @course.is_public == 0 | if @course.is_public == 0 | ||||
| @course.update_attributes(:is_public => 1) | @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 | else | ||||
| @course.update_attributes(:is_public => 0) | @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 | end | ||||
| if @course.is_public == 0 | if @course.is_public == 0 | ||||
| course_status = CourseStatus.find_by_course_id(@course.id) | course_status = CourseStatus.find_by_course_id(@course.id) | ||||
| @@ -1076,6 +1084,58 @@ class CoursesController < ApplicationController | |||||
| redirect_to course_url(@course, type: params[:type], page: params[:page]) | redirect_to course_url(@course, type: params[:type], page: params[:page]) | ||||
| end | 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 | def show | ||||
| # 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除 | # 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除 | ||||
| # if @course.is_delete == 1 && !User.current.admin? | # if @course.is_delete == 1 && !User.current.admin? | ||||
| @@ -1093,31 +1153,31 @@ 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 = 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_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 | @canShowRealName = User.current.member_of_course? @course | ||||
| @page = params[:page] ? params[:page].to_i + 1 : 0 | @page = params[:page] ? params[:page].to_i + 1 : 0 | ||||
| if params[:type].present? | if params[:type].present? | ||||
| case params[:type] | case params[:type] | ||||
| when "homework" | when "homework" | ||||
| @course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").order('updated_at desc') | |||||
| @course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").includes(:course_act).order('updated_at desc') | |||||
| when "news" | when "news" | ||||
| @course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc') | |||||
| @course_activities = course_activities.where("course_act_type = 'News'").includes(:course_act).order('updated_at desc') | |||||
| when "message" | when "message" | ||||
| @course_activities = course_activities.where("course_act_type = 'Message'").order('updated_at desc') | |||||
| @course_activities = course_activities.where("course_act_type = 'Message'").includes(:course_act).order('updated_at desc') | |||||
| when "poll" | when "poll" | ||||
| @course_activities = course_activities.where("course_act_type = 'Poll'").order('updated_at desc') | |||||
| @course_activities = course_activities.where("course_act_type = 'Poll'").includes(:course_act).order('updated_at desc') | |||||
| when "attachment" | when "attachment" | ||||
| @course_activities = course_activities.where("course_act_type = 'Attachment'").order('updated_at desc') | |||||
| @course_activities = course_activities.where("course_act_type = 'Attachment'").includes(:course_act).order('updated_at desc') | |||||
| when "journalsForMessage" | when "journalsForMessage" | ||||
| @course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc') | |||||
| @course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").includes(:course_act).order('updated_at desc') | |||||
| else | else | ||||
| @course_activities = course_activities.order('updated_at desc') | |||||
| @course_activities = course_activities.includes(:course_act).order('updated_at desc') | |||||
| end | end | ||||
| else | else | ||||
| @course_activities = course_activities.order('updated_at desc') | |||||
| @course_activities = course_activities.includes(:course_act).order('updated_at desc') | |||||
| end | end | ||||
| @course_activities_count = @course_activities.count | @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] | @type = params[:type] | ||||
| @left_nav_type = 1 | @left_nav_type = 1 | ||||
| @@ -1311,6 +1371,7 @@ class CoursesController < ApplicationController | |||||
| #删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到 | #删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到 | ||||
| def destroy | def destroy | ||||
| @course.delete! | @course.delete! | ||||
| CourseCache.update_course_act_updated_at_to_0_cache(@course.id) | |||||
| @course = nil | @course = nil | ||||
| redirect_to user_url(User.current) | redirect_to user_url(User.current) | ||||
| end | end | ||||
| @@ -600,6 +600,7 @@ class FilesController < ApplicationController | |||||
| end | end | ||||
| attachment.description = params[:description] | attachment.description = params[:description] | ||||
| attachment.save | attachment.save | ||||
| AttachmentsCache.update_course_attachments_cache(@course.id,attachment.id,0,{}) | |||||
| end | end | ||||
| end | end | ||||
| if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) | if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) | ||||
| @@ -14,6 +14,7 @@ class HomeworkCommonController < ApplicationController | |||||
| #unless params[:page] | #unless params[:page] | ||||
| # update_homework_time(@course.homework_commons) | # update_homework_time(@course.homework_commons) | ||||
| #end | #end | ||||
| search_ex = params[:search].to_s.strip.downcase | |||||
| search = "%#{params[:search].to_s.strip.downcase}%" | search = "%#{params[:search].to_s.strip.downcase}%" | ||||
| @new_homework = HomeworkCommon.new | @new_homework = HomeworkCommon.new | ||||
| @new_homework.homework_detail_manual = HomeworkDetailManual.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)) | @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) | ||||
| if @is_teacher | if @is_teacher | ||||
| #@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) | #@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 | else | ||||
| #@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) | #@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 | end | ||||
| #update_homework_time @homework_commons | #update_homework_time @homework_commons | ||||
| @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) | @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 | @homeworks = paginateHelper @homework_commons,10 | ||||
| #设置at已读 | #设置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| | @homeworks.each do |homework| | ||||
| # homework.journals_for_messages.each do |j| | # homework.journals_for_messages.each do |j| | ||||
| # User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} | # User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} | ||||
| @@ -74,11 +108,18 @@ class HomeworkCommonController < ApplicationController | |||||
| def update | def update | ||||
| if params[:homework_common] | 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.name = params[:homework_common][:name] | ||||
| @homework.description = params[:homework_common][:description] | @homework.description = params[:homework_common][:description] | ||||
| if params[:homework_common][:publish_time] == "" | if params[:homework_common][:publish_time] == "" | ||||
| @homework.publish_time = Date.today | @homework.publish_time = Date.today | ||||
| CourseCache.update_course_homeworks_cache(@homework.course.id,@homework.id,2,{:publish_time=>@homework.publish_time}) | |||||
| else | 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] | @homework.publish_time = params[:homework_common][:publish_time] | ||||
| end | end | ||||
| homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new | homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new | ||||
| @@ -233,8 +233,11 @@ class MembersController < ApplicationController | |||||
| role_ids = params[:membership][:role_ids] | role_ids = params[:membership][:role_ids] | ||||
| #role = Role.find(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") | if role_ids && role_ids.include?("10") | ||||
| StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id) | 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 | end | ||||
| #给新成员和老师发送加入课程的消息,发送者id放在CourseMessage的course_message_id字段中 | #给新成员和老师发送加入课程的消息,发送者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) | 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 | 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) | #user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id) | ||||
| if (params[:membership][:role_ids]) | if (params[:membership][:role_ids]) | ||||
| role = Role.find(params[:membership][:role_ids][0]) | role = Role.find(params[:membership][:role_ids][0]) | ||||
| @@ -324,23 +333,56 @@ class MembersController < ApplicationController | |||||
| end | end | ||||
| elsif @course | elsif @course | ||||
| if params[:membership] | 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]) | if (params[:membership][:role_ids]) | ||||
| role = Role.find(params[:membership][:role_ids][0]) | role = Role.find(params[:membership][:role_ids][0]) | ||||
| # 这里的判断只能通过角色名,可以弄成常量 | # 这里的判断只能通过角色名,可以弄成常量 | ||||
| attrs = params[:membership].dup | attrs = params[:membership].dup | ||||
| role_ids = attrs.delete(:role_ids) | role_ids = attrs.delete(:role_ids) | ||||
| course_count = CourseCache.course_count_cache(@course.id) | |||||
| if role_ids && role_ids.include?("10") | if role_ids && role_ids.include?("10") | ||||
| StudentsForCourse.create(:student_id => @member.user_id, :course_id =>@course.id) | 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 | else | ||||
| joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id) | joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id) | ||||
| joined.each do |join| | joined.each do |join| | ||||
| join.destroy | join.destroy | ||||
| end | end | ||||
| @member.course_group_id = 0 | @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 | 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) | if role.allowed_to?(:is_manager) | ||||
| @courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id) | @courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id) | ||||
| @courseInfo.save | @courseInfo.save | ||||
| @@ -61,12 +61,12 @@ class PraiseTreadController < ApplicationController | |||||
| end | end | ||||
| return | return | ||||
| end | end | ||||
| @pt.delete if !@pt.nil? | |||||
| @pt.destroy if !@pt.nil? | |||||
| #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 | #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 | ||||
| @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first | @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first | ||||
| @ptc.minus(1) if !@ptc.nil? | @ptc.minus(1) if !@ptc.nil? | ||||
| if @ptc.praise_num == 0 | if @ptc.praise_num == 0 | ||||
| @ptc.delete | |||||
| @ptc.destroy | |||||
| end | end | ||||
| end | end | ||||
| @@ -311,21 +311,63 @@ class ProjectsController < ApplicationController | |||||
| @author = params[:user_id].blank? ? nil : User.active.find(params[:user_id]) | @author = params[:user_id].blank? ? nil : User.active.find(params[:user_id]) | ||||
| @page = params[:page] ? params[:page].to_i + 1 : 0 | @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? | if User.current.member_of?(@project) || User.current.admin? | ||||
| case params[:type] | case params[:type] | ||||
| when nil | 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' | 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' | 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' | 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' | 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 | end | ||||
| else | 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 | end | ||||
| @type = params[:type] | @type = params[:type] | ||||
| # 版本库统计图 | # 版本库统计图 | ||||
| @@ -1044,6 +1044,7 @@ class StudentWorkController < ApplicationController | |||||
| @homework.student_works.each do |student_work| | @homework.student_works.each do |student_work| | ||||
| set_final_score @homework,student_work | set_final_score @homework,student_work | ||||
| student_work.save | student_work.save | ||||
| CourseCache.update_course_heroes_cache(@homework.course.id,student_work.user.id,0,{}) | |||||
| end | end | ||||
| end | end | ||||
| @@ -1072,6 +1073,7 @@ class StudentWorkController < ApplicationController | |||||
| @homework.student_works.each do |student_work| | @homework.student_works.each do |student_work| | ||||
| set_final_score @homework,student_work | set_final_score @homework,student_work | ||||
| student_work.save | student_work.save | ||||
| CourseCache.update_course_heroes_cache(@homework.course.id,student_work.user.id,0,{}) | |||||
| end | end | ||||
| @user_activity_id = params[:user_activity_id].to_i | @user_activity_id = params[:user_activity_id].to_i | ||||
| @hw_status = params[:hw_status].to_i | @hw_status = params[:hw_status].to_i | ||||
| @@ -90,53 +90,53 @@ class UsersController < ApplicationController | |||||
| # order 排序条件 | # order 排序条件 | ||||
| # subject 主题:搜索用(注意:搜索和列表调用同一方法,通过参数或者remote区分) | # subject 主题:搜索用(注意:搜索和列表调用同一方法,通过参数或者remote区分) | ||||
| def user_issues | def user_issues | ||||
| @subject = params[:subject] | |||||
| # author_id = params[:author_id] | |||||
| params[:assigned_to_id].to_i == 0 ? @assigned_to = nil : @assigned_to = params[:assigned_to_id].to_i | |||||
| params[:author_id].to_i == 0 ? author_id = nil : author_id = params[:author_id].to_i | |||||
| params[:project_id].to_i == 0 ? @project_id = nil : @project_id = params[:project_id] | |||||
| if @project_id.nil? | |||||
| if @assigned_to.nil? | |||||
| if author_id.nil? | |||||
| @issues = Issue.where("(author_id =? or assigned_to_id =? ) and subject like ?", | |||||
| @user.id , @user.id, "%#{@subject}%").order('updated_on desc') | |||||
| else | |||||
| @issues = Issue.where("author_id =? and subject like ?", | |||||
| author_id , "%#{@subject}%").order('updated_on desc') | |||||
| end | |||||
| @subject = params[:subject] | |||||
| # author_id = params[:author_id] | |||||
| params[:assigned_to_id].to_i == 0 ? @assigned_to = nil : @assigned_to = params[:assigned_to_id].to_i | |||||
| params[:author_id].to_i == 0 ? author_id = nil : author_id = params[:author_id].to_i | |||||
| params[:project_id].to_i == 0 ? @project_id = nil : @project_id = params[:project_id] | |||||
| if @project_id.nil? | |||||
| if @assigned_to.nil? | |||||
| if author_id.nil? | |||||
| @issues = Issue.where("(author_id =? or assigned_to_id =? ) and subject like ?", | |||||
| @user.id , @user.id, "%#{@subject}%").order('updated_on desc') | |||||
| else | else | ||||
| @issues = Issue.where("assigned_to_id =? and subject like ?", @assigned_to, "%#{@subject}%").order('updated_on desc') | |||||
| @issues = Issue.where("author_id =? and subject like ?", | |||||
| author_id , "%#{@subject}%").order('updated_on desc') | |||||
| end | end | ||||
| else | else | ||||
| if @assigned_to.nil? | |||||
| if author_id.nil? | |||||
| @issues = Issue.where("(author_id =? or assigned_to_id =? ) and project_id=? and subject like ?", | |||||
| (author_id ? author_id : @user.id) , @user.id, @project_id, "%#{@subject}%").order('updated_on desc') | |||||
| else | |||||
| @issues = Issue.where("author_id =? and project_id=? and subject like ?", | |||||
| author_id , @project_id, "%#{@subject}%").order('updated_on desc') | |||||
| end | |||||
| @issues = Issue.where("assigned_to_id =? and subject like ?", @assigned_to, "%#{@subject}%").order('updated_on desc') | |||||
| end | |||||
| else | |||||
| if @assigned_to.nil? | |||||
| if author_id.nil? | |||||
| @issues = Issue.where("(author_id =? or assigned_to_id =? ) and project_id=? and subject like ?", | |||||
| (author_id ? author_id : @user.id) , @user.id, @project_id, "%#{@subject}%").order('updated_on desc') | |||||
| else | else | ||||
| @issues = Issue.where("assigned_to_id =? and project_id=? and subject like ?", | |||||
| @assigned_to, @project_id, "%#{@subject}%").order('updated_on desc') | |||||
| @issues = Issue.where("author_id =? and project_id=? and subject like ?", | |||||
| author_id , @project_id, "%#{@subject}%").order('updated_on desc') | |||||
| end | end | ||||
| else | |||||
| @issues = Issue.where("assigned_to_id =? and project_id=? and subject like ?", | |||||
| @assigned_to, @project_id, "%#{@subject}%").order('updated_on desc') | |||||
| end | end | ||||
| @issues_filter = Issue.where("author_id =? or assigned_to_id =?", (author_id ? author_id : @user.id) , @user).order('updated_on desc') | |||||
| @issues_assigned_count = Issue.where("assigned_to_id =? and subject like ?", @user.id, "%#{@subject}%").count | |||||
| @issues_author_count = Issue.where("author_id =? and subject like ?", @user.id, "%#{@subject}%").count | |||||
| @issue_open_count = Issue.where(" (author_id =? or assigned_to_id =?) and status_id in (1,2,3,4,6)", (author_id ? author_id : @user.id) , @user).count | |||||
| @issue_close_count = Issue.where("(author_id =? or assigned_to_id =?) and status_id = 5", (author_id ? author_id : @user.id) , @user.id).count | |||||
| end | |||||
| @issues_filter = Issue.where("author_id =? or assigned_to_id =?", (author_id ? author_id : @user.id) , @user).order('updated_on desc') | |||||
| @issues_assigned_count = Issue.where("assigned_to_id =? and subject like ?", @user.id, "%#{@subject}%").count | |||||
| @issues_author_count = Issue.where("author_id =? and subject like ?", @user.id, "%#{@subject}%").count | |||||
| @issue_open_count = Issue.where(" (author_id =? or assigned_to_id =?) and status_id in (1,2,3,4,6)", (author_id ? author_id : @user.id) , @user).count | |||||
| @issue_close_count = Issue.where("(author_id =? or assigned_to_id =?) and status_id = 5", (author_id ? author_id : @user.id) , @user.id).count | |||||
| # 导出excel的issues | # 导出excel的issues | ||||
| @excel_issues = @issues | @excel_issues = @issues | ||||
| @issue_count = @issues.count | |||||
| @limit = 10 | |||||
| @is_remote = true | |||||
| @issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1 | |||||
| @offset ||= @issue_pages.offset | |||||
| @issues = paginateHelper @issues, @limit | |||||
| @issue_count = @issues.count | |||||
| @limit = 10 | |||||
| @is_remote = true | |||||
| @issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1 | |||||
| @offset ||= @issue_pages.offset | |||||
| @issues = paginateHelper @issues, @limit | |||||
| respond_to do |format| | respond_to do |format| | ||||
| format.html{render :layout => 'static_base'} | format.html{render :layout => 'static_base'} | ||||
| @@ -536,16 +536,22 @@ class UsersController < ApplicationController | |||||
| member = Course.find(@msg.course_id).members.where(:user_id=>apply_user.id).all[0] | member = Course.find(@msg.course_id).members.where(:user_id=>apply_user.id).all[0] | ||||
| member.role_ids = integer_ids | member.role_ids = integer_ids | ||||
| #删除为学生的记录 | #删除为学生的记录 | ||||
| course_count = CourseCache.course_count_cache(@msg.course_id) | |||||
| unless member.role_ids.include?(10) | unless member.role_ids.include?(10) | ||||
| joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@msg.course_id) | joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@msg.course_id) | ||||
| joined.each do |join| | joined.each do |join| | ||||
| join.delete | join.delete | ||||
| end | end | ||||
| #学生数-1 | |||||
| CourseCache.update_course_count_cache(@msg.course_id,{:student_num=>course_count[:student_num]-1}) | |||||
| end | end | ||||
| member.course_group_id = 0 | member.course_group_id = 0 | ||||
| member.save | member.save | ||||
| CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) | |||||
| #老师数+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) | @msg.update_attributes(:status=>1,:viewed=>1) | ||||
| else | else | ||||
| members = [] | members = [] | ||||
| @@ -1626,16 +1632,41 @@ class UsersController < ApplicationController | |||||
| #显示更多用户课程 | #显示更多用户课程 | ||||
| def user_courses4show | 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 | end | ||||
| #显示更多用户项目 | #显示更多用户项目 | ||||
| def user_projects4show | 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 | end | ||||
| def user_course_activities | def user_course_activities | ||||
| @@ -3647,7 +3678,7 @@ class UsersController < ApplicationController | |||||
| if params[:is_delete] && params[:is_delete] == '1' | if params[:is_delete] && params[:is_delete] == '1' | ||||
| @courses = @syllabus.courses.where("is_delete = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") | @courses = @syllabus.courses.where("is_delete = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") | ||||
| else | else | ||||
| @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") | |||||
| @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") | |||||
| end | end | ||||
| respond_to do |format| | respond_to do |format| | ||||
| format.js | format.js | ||||
| @@ -3665,6 +3696,14 @@ class UsersController < ApplicationController | |||||
| member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") | member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") | ||||
| end | end | ||||
| unless member.empty? | 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) | member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) | ||||
| end | end | ||||
| if @project | if @project | ||||
| @@ -420,6 +420,9 @@ module ApiHelper | |||||
| if course_activity | if course_activity | ||||
| course_activity.updated_at = Time.now | course_activity.updated_at = Time.now | ||||
| course_activity.save | 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 | ||||
| end | end | ||||
| #首页动态更新 | #首页动态更新 | ||||
| @@ -436,6 +439,8 @@ module ApiHelper | |||||
| if forge_activity | if forge_activity | ||||
| forge_activity.updated_at = Time.now | forge_activity.updated_at = Time.now | ||||
| forge_activity.save | 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 | ||||
| end | end | ||||
| #组织动态更新 | #组织动态更新 | ||||
| @@ -309,7 +309,7 @@ module ApplicationHelper | |||||
| case type | case type | ||||
| when "HomeworkCommon" | when "HomeworkCommon" | ||||
| if course_contributor_score.nil? | 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 | else | ||||
| score = course_contributor_score.homework_journal_num.to_i + 1 | score = course_contributor_score.homework_journal_num.to_i + 1 | ||||
| course_contributor_score.update_column(:homework_journal_num, score) | course_contributor_score.update_column(:homework_journal_num, score) | ||||
| @@ -317,47 +317,69 @@ module ApplicationHelper | |||||
| # 课程留言 | # 课程留言 | ||||
| when "Course" | when "Course" | ||||
| if course_contributor_score.nil? | 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 | else | ||||
| score = course_contributor_score.journal_num.to_i + 1 | score = course_contributor_score.journal_num.to_i + 1 | ||||
| course_contributor_score.update_column(:journal_num, score) | course_contributor_score.update_column(:journal_num, score) | ||||
| end | end | ||||
| when "Message" | when "Message" | ||||
| if course_contributor_score.nil? | 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 | else | ||||
| score = course_contributor_score.message_num.to_i + 1 | score = course_contributor_score.message_num.to_i + 1 | ||||
| course_contributor_score.update_column(:message_num, score) | course_contributor_score.update_column(:message_num, score) | ||||
| end | end | ||||
| when "MessageReply" | when "MessageReply" | ||||
| if course_contributor_score.nil? | 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 | else | ||||
| score = course_contributor_score.message_reply_num.to_i + 1 | score = course_contributor_score.message_reply_num.to_i + 1 | ||||
| course_contributor_score.update_column(:message_reply_num, score) | course_contributor_score.update_column(:message_reply_num, score) | ||||
| end | end | ||||
| when "NewReply" | when "NewReply" | ||||
| if course_contributor_score.nil? | 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 | else | ||||
| score = course_contributor_score.news_reply_num.to_i + 1 | score = course_contributor_score.news_reply_num.to_i + 1 | ||||
| course_contributor_score.update_column(:news_reply_num, score) | course_contributor_score.update_column(:news_reply_num, score) | ||||
| end | end | ||||
| when "News" | when "News" | ||||
| if course_contributor_score.nil? | 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 | else | ||||
| score = course_contributor_score.news_num.to_i + 1 | score = course_contributor_score.news_num.to_i + 1 | ||||
| course_contributor_score.update_column(:news_num, score) | course_contributor_score.update_column(:news_num, score) | ||||
| end | end | ||||
| when "Attachment" | when "Attachment" | ||||
| if course_contributor_score.nil? | 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 | else | ||||
| score = course_contributor_score.resource_num.to_i + 1 | score = course_contributor_score.resource_num.to_i + 1 | ||||
| course_contributor_score.update_column(:resource_num, score) | course_contributor_score.update_column(:resource_num, score) | ||||
| end | end | ||||
| 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 | end | ||||
| # 删除某条记录相应减少课程统计数 | # 删除某条记录相应减少课程统计数 | ||||
| @@ -401,6 +423,29 @@ module ApplicationHelper | |||||
| course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score) | course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score) | ||||
| end | end | ||||
| 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 | end | ||||
| # Added by young | # Added by young | ||||
| @@ -3258,6 +3303,9 @@ int main(int argc, char** argv){ | |||||
| if course_activity | if course_activity | ||||
| course_activity.updated_at = Time.now | course_activity.updated_at = Time.now | ||||
| course_activity.save | 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 | ||||
| end | end | ||||
| #首页动态更新 | #首页动态更新 | ||||
| @@ -3274,6 +3322,8 @@ int main(int argc, char** argv){ | |||||
| if forge_activity | if forge_activity | ||||
| forge_activity.updated_at = Time.now | forge_activity.updated_at = Time.now | ||||
| forge_activity.save | 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 | ||||
| end | end | ||||
| #组织动态更新 | #组织动态更新 | ||||
| @@ -3498,6 +3548,17 @@ def get_reply_parents parents_rely, comment | |||||
| parents_rely | parents_rely | ||||
| end | 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 | def get_reply_parents_no_root parents_rely, comment | ||||
| if !comment.parent.nil? && !comment.parent.parent.nil? | if !comment.parent.nil? && !comment.parent.parent.nil? | ||||
| @@ -3507,6 +3568,19 @@ def get_reply_parents_no_root parents_rely, comment | |||||
| parents_rely | parents_rely | ||||
| end | 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 | def get_all_children_ex result, jour | ||||
| if jour.kind_of? Message | if jour.kind_of? Message | ||||
| jour.children.includes(:author, :praise_tread_cache).each do |jour_child| | jour.children.includes(:author, :praise_tread_cache).each do |jour_child| | ||||
| @@ -3842,6 +3916,53 @@ def homework_type_option | |||||
| type | type | ||||
| end | 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 | |||||
| def add_reply_adapter obj, options | def add_reply_adapter obj, options | ||||
| #modify by nwb | #modify by nwb | ||||
| #添加对课程留言的支持 | #添加对课程留言的支持 | ||||
| @@ -3882,3 +4003,9 @@ def add_reply_adapter obj, options | |||||
| # end | # end | ||||
| end | end | ||||
| @@ -16,7 +16,8 @@ module CoursesHelper | |||||
| # 推荐的精品课程 | # 推荐的精品课程 | ||||
| def excellent_course_recommend new_course | def excellent_course_recommend new_course | ||||
| q = "%#{new_course.name.strip}%" | 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 | end | ||||
| # 查询符合条件的精品课程 | # 查询符合条件的精品课程 | ||||
| @@ -40,6 +41,29 @@ module CoursesHelper | |||||
| return excellent_courses | return excellent_courses | ||||
| end | 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 | def visible_excellent_course obj | ||||
| # if course.is_pu | # if course.is_pu | ||||
| @@ -804,14 +828,31 @@ module CoursesHelper | |||||
| def visable_attachemnts_incourse course | def visable_attachemnts_incourse course | ||||
| return[] unless course | return[] unless course | ||||
| result = [] | result = [] | ||||
| is_teacher = User.current.allowed_to?(:as_teacher,course) | |||||
| is_member = User.current.member_of_course?(course) | |||||
| course.attachments.each do |attachment| | 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 | result << attachment | ||||
| end | end | ||||
| end | end | ||||
| result | result | ||||
| end | 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 | def visable_course_homework course | ||||
| if User.current.admin? || User.current.allowed_to?(:as_teacher,course) | if User.current.admin? || User.current.allowed_to?(:as_teacher,course) | ||||
| homework_num = course.homework_commons.count | homework_num = course.homework_commons.count | ||||
| @@ -821,6 +862,28 @@ module CoursesHelper | |||||
| homework_num | homework_num | ||||
| end | 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 | def zh_course_role role | ||||
| if role == "TeachingAsistant" | if role == "TeachingAsistant" | ||||
| result = l(:label_TA) | result = l(:label_TA) | ||||
| @@ -911,6 +974,18 @@ module CoursesHelper | |||||
| homework_scores = Member.find_by_sql(sql_select) | homework_scores = Member.find_by_sql(sql_select) | ||||
| end | 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) | def contributor_course_scor(course_id) | ||||
| ccs = CourseContributorScore.find_by_sql("SELECT ccs.*, (message_num*2 + message_reply_num + news_reply_num + news_num + | 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 | 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;") | con_score desc limit 6;") | ||||
| end | 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 | def get_user_member_roles_course course, user, role | ||||
| members = course.members.where("user_id = #{user.id}") | 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") | @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") | ||||
| before_save :files_to_final_location | 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_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 | 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 | # add by nwb | ||||
| # 获取所有可公开的资源文件列表 | # 获取所有可公开的资源文件列表 | ||||
| @@ -683,6 +684,26 @@ class Attachment < ActiveRecord::Base | |||||
| down_course_score_num(self.container_id, self.author_id, "Attachment") | down_course_score_num(self.container_id, self.author_id, "Attachment") | ||||
| end | end | ||||
| 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 | end | ||||
| # Delete the previous articles index in Elasticsearch | # Delete the previous articles index in Elasticsearch | ||||
| @@ -23,8 +23,8 @@ class BlogComment < ActiveRecord::Base | |||||
| after_save :add_user_activity | after_save :add_user_activity | ||||
| after_update :update_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| | scope :like, lambda {|arg| | ||||
| if arg.blank? | 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 | # 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 | ||||
| # 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 | end | ||||
| @@ -40,7 +40,8 @@ class Comment < ActiveRecord::Base | |||||
| belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | ||||
| validates_presence_of :commented, :author, :comments | validates_presence_of :commented, :author, :comments | ||||
| safe_attributes 'comments','parent_id','reply_id','comments_count' | safe_attributes 'comments','parent_id','reply_id','comments_count' | ||||
| after_create :act_as_system_message, :act_as_student_score #:send_mail, | |||||
| after_create :act_as_system_message, :act_as_student_score,:update_cache_add #:send_mail, | |||||
| before_destroy :update_cache_delete | |||||
| after_destroy :down_course_score | after_destroy :down_course_score | ||||
| def act_as_system_message | def act_as_system_message | ||||
| @@ -60,8 +61,8 @@ class Comment < ActiveRecord::Base | |||||
| # #content = strip_html self.comments.html_safe, 200 | # #content = strip_html self.comments.html_safe, 200 | ||||
| # #ws.comment_template self.commented.author_id, "blog_comment", self.id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content | # #ws.comment_template self.commented.author_id, "blog_comment", self.id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content | ||||
| # end | # end | ||||
| end | |||||
| end | end | ||||
| end | |||||
| def send_mail | def send_mail | ||||
| if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') | if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') | ||||
| @@ -119,4 +120,18 @@ class Comment < ActiveRecord::Base | |||||
| self.comments | self.comments | ||||
| end | 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 | end | ||||
| @@ -5,8 +5,9 @@ class CourseActivity < ActiveRecord::Base | |||||
| belongs_to :course | belongs_to :course | ||||
| belongs_to :user | belongs_to :user | ||||
| has_many :user_acts, :class_name => 'UserAcivity',:as =>:act | 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 | 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 | message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first | ||||
| end | end | ||||
| 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 | end | ||||
| @@ -20,8 +20,9 @@ class ForgeActivity < ActiveRecord::Base | |||||
| validates :forge_act_id,presence: true | validates :forge_act_id,presence: true | ||||
| validates :forge_act_type, presence: true | validates :forge_act_type, presence: true | ||||
| has_many :user_acts, :class_name => 'UserAcivity',:as =>:act | 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 = OrgActivity.where("org_act_type='#{self.forge_act_type.to_s}' and org_act_id = '#{self.forge_act_id}'") | ||||
| org_acts.destroy_all | org_acts.destroy_all | ||||
| end | 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 | end | ||||
| @@ -31,10 +31,11 @@ class HomeworkCommon < ActiveRecord::Base | |||||
| :description => :description, | :description => :description, | ||||
| :author => :author, | :author => :author, | ||||
| :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} | :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_save :act_as_course_activity | ||||
| after_destroy :delete_kindeditor_assets | after_destroy :delete_kindeditor_assets | ||||
| before_destroy :update_cache_delete | |||||
| #作业类型 | #作业类型 | ||||
| def homework_type_ch | def homework_type_ch | ||||
| @@ -171,6 +172,20 @@ class HomeworkCommon < ActiveRecord::Base | |||||
| end | end | ||||
| 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 | delegate :language_name, :language, :to => :homework_detail_programing | ||||
| end | end | ||||
| @@ -93,7 +93,7 @@ class Issue < ActiveRecord::Base | |||||
| after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, | 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 | 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_destroy :down_user_score, :decrease_issues_count | ||||
| # after_create :be_user_score | # after_create :be_user_score | ||||
| # end | # end | ||||
| @@ -134,6 +134,7 @@ class Issue < ActiveRecord::Base | |||||
| # Should be after_create but would be called before previous after_save callbacks | # Should be after_create but would be called before previous after_save callbacks | ||||
| after_save :after_create_from_copy | after_save :after_create_from_copy | ||||
| after_destroy :update_parent_attributes | after_destroy :update_parent_attributes | ||||
| before_destroy :update_cache_delete | |||||
| #动态的更新 | #动态的更新 | ||||
| def update_activity | def update_activity | ||||
| @@ -1671,6 +1672,13 @@ class Issue < ActiveRecord::Base | |||||
| end | end | ||||
| def update_cache | |||||
| IssueCache.update_issue_cache(self.id,self) | |||||
| end | |||||
| def update_cache_delete | |||||
| IssueCache.delete_issue_cache(self.id) | |||||
| end | |||||
| end | end | ||||
| @@ -76,11 +76,12 @@ class JournalsForMessage < ActiveRecord::Base | |||||
| after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, | 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_at_message(:notes, :user_id), :act_as_user_feedback_message, | ||||
| :act_as_principal_activity, :act_as_student_score | :act_as_principal_activity, :act_as_student_score | ||||
| after_create :reset_counters! | |||||
| after_create :reset_counters!,:update_cache_add | |||||
| #after_update :update_activity | #after_update :update_activity | ||||
| # after_destroy :reset_counters! | # after_destroy :reset_counters! | ||||
| after_save :be_user_score | after_save :be_user_score | ||||
| after_destroy :down_user_score, :down_course_score | after_destroy :down_user_score, :down_course_score | ||||
| before_destroy :update_cache_delete | |||||
| # default_scope { where('m_parent_id IS NULL') } | # default_scope { where('m_parent_id IS NULL') } | ||||
| @@ -345,8 +346,31 @@ class JournalsForMessage < ActiveRecord::Base | |||||
| self.notes | self.notes | ||||
| end | 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 | |||||
| def set_children_readed_delay | def set_children_readed_delay | ||||
| # fetch_user_leaveWord_reply(self).update_all(:is_readed => true, :status => false) | # fetch_user_leaveWord_reply(self).update_all(:is_readed => true, :status => false) | ||||
| end | end | ||||
| end | end | ||||
| @@ -82,10 +82,11 @@ class Message < ActiveRecord::Base | |||||
| validate :cannot_reply_to_locked_topic, :on => :create | validate :cannot_reply_to_locked_topic, :on => :create | ||||
| # after_create :add_author_as_watcher, :reset_counters!, :add_boards_count | # 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_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_save :be_user_score | ||||
| before_destroy :update_cache_delete | |||||
| scope :visible, lambda {|*args| | scope :visible, lambda {|*args| | ||||
| includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *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 | def delete_org_activities | ||||
| OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all | OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all | ||||
| end | 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 | end | ||||
| @@ -65,9 +65,9 @@ class News < ActiveRecord::Base | |||||
| :author_key => :author_id | :author_key => :author_id | ||||
| acts_as_watchable | acts_as_watchable | ||||
| after_create :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score,: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_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score,: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| | scope :visible, lambda {|*args| | ||||
| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *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 | ||||
| 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 | end | ||||
| @@ -4,6 +4,8 @@ class PraiseTread < ActiveRecord::Base | |||||
| belongs_to :praise_tread_object, polymorphic: true | belongs_to :praise_tread_object, polymorphic: true | ||||
| #after_create :be_user_score | #after_create :be_user_score | ||||
| #after_destroy :down_user_score | #after_destroy :down_user_score | ||||
| after_create :set_praise_cache_true | |||||
| before_destroy :set_praise_cache_false | |||||
| include UserScoreHelper | include UserScoreHelper | ||||
| def self.find_object_by_type_and_id(type,id) | def self.find_object_by_type_and_id(type,id) | ||||
| @obj = nil | @obj = nil | ||||
| @@ -90,9 +92,19 @@ class PraiseTread < ActiveRecord::Base | |||||
| end | end | ||||
| def self.praised(activity) | 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 | ||||
| end | end | ||||
| @@ -7,11 +7,13 @@ class PraiseTreadCache < ActiveRecord::Base | |||||
| when 0 | when 0 | ||||
| self.update_attribute(:tread_num, self.tread_num.to_i + num) | self.update_attribute(:tread_num, self.tread_num.to_i + num) | ||||
| when 1 | 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) | self.update_attribute(:praise_num, self.praise_num.to_i + num) | ||||
| end | end | ||||
| end | end | ||||
| def minus(num) | 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) | self.update_attribute(:praise_num, self.praise_num.to_i - num) | ||||
| end | end | ||||
| end | end | ||||
| @@ -497,6 +497,7 @@ class Project < ActiveRecord::Base | |||||
| Project.transaction do | Project.transaction do | ||||
| archive! | archive! | ||||
| end | end | ||||
| ProjectCache.update_project_act_updated_at_to_0_cache(self.id) | |||||
| true | true | ||||
| end | end | ||||
| @@ -18,6 +18,7 @@ class StudentWork < ActiveRecord::Base | |||||
| before_destroy :delete_praise | before_destroy :delete_praise | ||||
| before_save :set_program_score, :set_src | before_save :set_program_score, :set_src | ||||
| after_save :update_score_cache | |||||
| after_create :act_as_message | after_create :act_as_message | ||||
| acts_as_attachable | 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) | self.course_messages << CourseMessage.new(:user_id => self.user_id, :course_id => self.homework_common.course_id, :viewed => false, :status => false) | ||||
| end | end | ||||
| 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 | end | ||||
| @@ -199,6 +199,7 @@ class CoursesService | |||||
| if params[:type] == 0 | if params[:type] == 0 | ||||
| course_count = CourseCache.course_count_cache(c.id) | |||||
| if apply_user.member_of_course?(c) | if apply_user.member_of_course?(c) | ||||
| #将角色改为老师或者教辅 | #将角色改为老师或者教辅 | ||||
| member = c.members.where(:user_id=>apply_user.id).all[0] | member = c.members.where(:user_id=>apply_user.id).all[0] | ||||
| @@ -209,10 +210,16 @@ class CoursesService | |||||
| joined.each do |join| | joined.each do |join| | ||||
| join.destroy | join.destroy | ||||
| end | end | ||||
| #学生数-1 | |||||
| CourseCache.update_course_count_cache(c.id,{:student_num=>course_count[:student_num]-1}) | |||||
| end | end | ||||
| member.course_group_id = 0 | member.course_group_id = 0 | ||||
| member.save | 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) | 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) | messages.update_attributes(:status=>1,:viewed=>1) | ||||
| else | else | ||||
| @@ -629,6 +636,9 @@ class CoursesService | |||||
| if params[:invite_code].present? | if params[:invite_code].present? | ||||
| role_ids = params[:role] | role_ids = params[:role] | ||||
| role_str = role_ids.join(",") | 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") | if role_ids.include?("10") && !role_ids.include?("7") && !role_ids.include?("9") | ||||
| members = [] | members = [] | ||||
| members << Member.new(:role_ids => [10], :user_id => current_user.id) | members << Member.new(:role_ids => [10], :user_id => current_user.id) | ||||
| @@ -638,6 +648,8 @@ class CoursesService | |||||
| go_coursegroup_flag = 1 if course.course_groups | go_coursegroup_flag = 1 if course.course_groups | ||||
| course_id = course.id | course_id = course.id | ||||
| send_wechat_join_class_notice current_user,course,10,0 | 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 | else | ||||
| is_stu = false | is_stu = false | ||||
| if role_ids.include?("10") | if role_ids.include?("10") | ||||
| @@ -649,6 +661,8 @@ class CoursesService | |||||
| go_coursegroup_flag = 1 if course.course_groups | go_coursegroup_flag = 1 if course.course_groups | ||||
| course_id = course.id | course_id = course.id | ||||
| send_wechat_join_class_notice current_user,course,10,0 | 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 | 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 | 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,7 +50,7 @@ | |||||
| </script> | </script> | ||||
| <style type="text/css"> | <style type="text/css"> | ||||
| </style> | </style> | ||||
| <% course_activities.includes(:course_act).each do |activity| if course_activities %> | |||||
| <% course_activities.each do |activity| if course_activities %> | |||||
| <script> | <script> | ||||
| $(function () { | $(function () { | ||||
| sd_create_editor_from_data(<%= activity.id%>, null, "100%", "<%= activity.class.to_s %>"); | sd_create_editor_from_data(<%= activity.id%>, null, "100%", "<%= activity.class.to_s %>"); | ||||
| @@ -9,11 +9,13 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| <p class="sy_cgrey ml20"> | <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 %> | <% if homework_count > 0 %> | ||||
| 作业<span class="sy_cir_grey ml5 mr5"><%=homework_count %></span> | 作业<span class="sy_cir_grey ml5 mr5"><%=homework_count %></span> | ||||
| <% end %> | <% 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 %> | <% if file_count > 0 %> | ||||
| 资源<span class="sy_cir_grey ml5 mr5"><%=file_count %></span> | 资源<span class="sy_cir_grey ml5 mr5"><%=file_count %></span> | ||||
| <% end %> | <% end %> | ||||
| @@ -52,7 +52,8 @@ | |||||
| <% else %> | <% else %> | ||||
| <% @homework_commons.each_with_index do |homework_common,index |%> | <% @homework_commons.each_with_index do |homework_common,index |%> | ||||
| <li class="pr10"> | <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> | </li> | ||||
| <% end%> | <% end%> | ||||
| <% end %> | <% end %> | ||||
| @@ -1,7 +1,13 @@ | |||||
| <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> | <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> | ||||
| <% teacher_num = TeacherAndAssistantCount(@course) %> | |||||
| <% student_num = studentCount(@course) %> | |||||
| <% course_file_num = visable_attachemnts_incourse(@course).count %> | |||||
| <%# teacher_num = TeacherAndAssistantCount(@course) %> | |||||
| <%# student_num = studentCount(@course) %> | |||||
| <%# course_file_num = visable_attachemnts_incourse(@course).count %> | |||||
| <% 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"> | <p class="sy_cgrey mb10 mr20"> | ||||
| <%= link_to(@course.teacher.show_name, user_path(@course.teacher), :class => 'sy_cgrey') %> | <%= link_to(@course.teacher.show_name, user_path(@course.teacher), :class => 'sy_cgrey') %> | ||||
| > | > | ||||
| @@ -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"> | <div id="homepageLeftMenuCourses"> | ||||
| <ul class="user_sub_menu" id="user_courses_li"> | <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} %> | <%= 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"> | <div id="homepageLeftMenuForge"> | ||||
| <ul class="user_sub_menu" id="user_projects_li"> | <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} %> | <%= render :partial => 'layouts/user_projects', :locals => {:projects => projects,:user => @user, :all_count => all_count, :page => 0} %> | ||||
| @@ -1,4 +1,5 @@ | |||||
| <% courses.each do |course|%> | <% courses.each do |course|%> | ||||
| <% course = Course.find(course[:id])%> | |||||
| <li class="pr"> | <li class="pr"> | ||||
| <span class="user_icons_class"></span> | <span class="user_icons_class"></span> | ||||
| <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) %> | <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) %> | ||||
| @@ -1,4 +1,5 @@ | |||||
| <% projects.each do |project|%> | <% projects.each do |project|%> | ||||
| <% project = Project.find(project[:id])%> | |||||
| <li> | <li> | ||||
| <span class="user_icons_class"></span> | <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 %> | <% 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_model %> | ||||
| <%# course_file_num = Attachment.where(:container_type => "Course", :container_id => @course.id).count %> | <%# 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)) %> | <% 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> | <!DOCTYPE html> | ||||
| <html lang="en" xmlns="http://www.w3.org/1999/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_l fl" id="courseLSide"> | ||||
| <div class="sy_class_leftnav mb12"> | <div class="sy_class_leftnav mb12"> | ||||
| <ul class="accordion"> | <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"> | <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> | </li> | ||||
| <% end %> | <% end %> | ||||
| <% course_board = @course.boards.where("parent_id is NULL").first %> | <% 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} %> | <%= render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board} %> | ||||
| </div> | </div> | ||||
| <% end %> | <% 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"> | <li id="sy_03" class="sy_icons_hwork"> | ||||
| <a href="<%= homework_common_index_path(:course => @course.id) %>">作业<span><%=homework_num %></span></a> | <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 %> | <%= 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> | </li> | ||||
| <% end %> | <% end %> | ||||
| <% unless show_nav?(@course.news.count) %> | |||||
| <% unless show_nav?(count_data[:news_count]) %> | |||||
| <li id="sy_04" class="sy_icons_news"> | <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 %> | <%= link_to( "",new_course_news_path(@course,:is_new=>1), :class => 'sy_class_add', :title =>"#{l(:label_course_news_new)}") if is_teacher %> | ||||
| </li> | </li> | ||||
| <% end %> | <% end %> | ||||
| @@ -164,7 +164,8 @@ | |||||
| <li id="user_01" class="user_icons_course"> | <li id="user_01" class="user_icons_course"> | ||||
| <%= link_to '班级',{:controller => "users", :action => "user_courselist", :id => @user}, :id => "user_course_list" %> | <%= link_to '班级',{:controller => "users", :action => "user_courselist", :id => @user}, :id => "user_course_list" %> | ||||
| <font class="show-all-sub"><%= link_to '全部',{:controller => "users", :action => "user_courselist", :id => @user}, :style => "color:#aaa;" %></font> | <font class="show-all-sub"><%= link_to '全部',{:controller => "users", :action => "user_courselist", :id => @user}, :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"> | <div class="<%= courses.empty? ? 'none' : ''%>" id="homepage_left_course_list"> | ||||
| <%=render :partial => 'layouts/homepage_left_course_list', :locals => {:courses => courses} %> | <%=render :partial => 'layouts/homepage_left_course_list', :locals => {:courses => courses} %> | ||||
| </div> | </div> | ||||
| @@ -192,7 +193,8 @@ | |||||
| <li id="user_06" class="user_icons_project"> | <li id="user_06" class="user_icons_project"> | ||||
| <%= link_to '项目',{:controller => "users", :action => "user_projectlist", :id => @user}, :id => 'user_project_list'%> | <%= link_to '项目',{:controller => "users", :action => "user_projectlist", :id => @user}, :id => 'user_project_list'%> | ||||
| <font class="show-all-sub"><%= link_to '全部',{:controller => "users", :action => "user_projectlist", :id => @user}, :style => "color:#aaa;" %></font> | <font class="show-all-sub"><%= link_to '全部',{:controller => "users", :action => "user_projectlist", :id => @user}, :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"> | <div class="<%= projects.empty? ? 'none' : ''%>" id="homepage_left_project_list"> | ||||
| <%=render :partial => 'layouts/homepage_left_project_list', :locals => {:projects => projects} %> | <%=render :partial => 'layouts/homepage_left_project_list', :locals => {:projects => projects} %> | ||||
| </div> | </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="点赞" > | <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> | <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> | </a> | ||||
| <% else %> | <% 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="取消点赞" > | <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> | <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> | </a> | ||||
| <% end %> | |||||
| <% end %> | |||||
| @@ -81,13 +81,18 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| </div> | </div> | ||||
| <% all_comments = []%> | |||||
| <%# 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 %> | |||||
| <div class="container-big-grey"> | <div class="container-big-grey"> | ||||
| <div id="activity_post_reply_<%=user_activity_id %>"> | <div id="activity_post_reply_<%=user_activity_id %>"> | ||||
| <%=render :partial => 'projects/project_message_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | <%=render :partial => 'projects/project_message_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | ||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| user_card_show_hide(); | user_card_show_hide(); | ||||
| @@ -30,24 +30,35 @@ | |||||
| <% forge_acts.each do |activity| -%> | <% forge_acts.each do |activity| -%> | ||||
| <script> | <script> | ||||
| $(function () { | $(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> | </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" %> | <% 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" %> | <% 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 --> | <!--message --> | ||||
| <% when "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 --> | <!--Attachment --> | ||||
| <% when "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" %> | <% 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 %> | <% 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)%> | <% user = User.find(project.user_id)%> | ||||
| <div class="container-big mt10"> | <div class="container-big mt10"> | ||||
| <div class="pr"> | <div class="pr"> | ||||
| @@ -1,5 +1,8 @@ | |||||
| <ul> | <ul> | ||||
| <% comments.each do |comment| %> | <% comments.each do |comment| %> | ||||
| <% if type == 'Message' %> | |||||
| <% comment = MessagesCache.message_cache(comment[:id]) #Message.find(comment[:id]) %> | |||||
| <% end %> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| showNormalImage('reply_content_<%= comment.id %>'); | showNormalImage('reply_content_<%= comment.id %>'); | ||||
| @@ -39,13 +39,16 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| </div> | </div> | ||||
| <%# 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"> | <div class="homepagePostReply"> | ||||
| <div id="activity_post_reply_<%=user_activity_id %>"> | <div id="activity_post_reply_<%=user_activity_id %>"> | ||||
| <%=render :partial => 'users/user_journal_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | <%=render :partial => 'users/user_journal_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | ||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| user_card_show_hide(); | user_card_show_hide(); | ||||
| @@ -2,7 +2,7 @@ | |||||
| <div class="homepagePostBrief"> | <div class="homepagePostBrief"> | ||||
| <div class="homepagePostPortrait"> | <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 => "用户头像" %> | <%= 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> | ||||
| <div class="homepagePostDes"> | <div class="homepagePostDes"> | ||||
| <div class="homepagePostTo break_word"> | <div class="homepagePostTo break_word"> | ||||
| @@ -79,12 +79,18 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| </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 = ReplyCache.message_replys_cache(activity.id) %> | |||||
| <% count = all_replies.count %> | |||||
| <div class="homepagePostReply"> | <div class="homepagePostReply"> | ||||
| <div id="activity_post_reply_<%=user_activity_id %>"> | <div id="activity_post_reply_<%=user_activity_id %>"> | ||||
| <%=render :partial => 'users/course_message_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | <%=render :partial => 'users/course_message_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | ||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| user_card_show_hide(); | user_card_show_hide(); | ||||
| @@ -63,13 +63,15 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| </div> | </div> | ||||
| <% all_comments = ReplyCache.news_replys_cache(activity.id)%> | |||||
| <%# count=activity.comments.count %> | |||||
| <% count=all_comments.count %> | |||||
| <div class="homepagePostReply"> | <div class="homepagePostReply"> | ||||
| <div id="activity_post_reply_<%=user_activity_id %>"> | <div id="activity_post_reply_<%=user_activity_id %>"> | ||||
| <%=render :partial => 'users/course_news_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | <%=render :partial => 'users/course_news_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | ||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| user_card_show_hide(); | user_card_show_hide(); | ||||
| @@ -1,4 +1,6 @@ | |||||
| <% count=activity.journals_for_messages.count %> | |||||
| <% all_replys = ReplyCache.homework_replys_cache(activity.id) %> | |||||
| <%# count=activity.journals_for_messages.count %> | |||||
| <% count=all_replys.count %> | |||||
| <% comments = activity.journals_for_messages.reorder("created_on desc") %> | <% comments = activity.journals_for_messages.reorder("created_on desc") %> | ||||
| <% no_children_comments = get_no_children_comments comments %> | <% no_children_comments = get_no_children_comments comments %> | ||||
| <div class="homepagePostReply" id="homework_post_reply_<%= user_activity_id %>"> | <div class="homepagePostReply" id="homework_post_reply_<%= user_activity_id %>"> | ||||
| @@ -1,5 +1,13 @@ | |||||
| <ul> | <ul> | ||||
| <% comments.each do |comment| %> | <% 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"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| showNormalImage('reply_content_<%= comment.id %>'); | showNormalImage('reply_content_<%= comment.id %>'); | ||||
| @@ -24,7 +32,9 @@ | |||||
| <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> | <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> | ||||
| </span> | </span> | ||||
| <% if type == 'Message' %> | <% 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') %> | <% if !topic.locked? && authorize_for('messages', 'reply') %> | ||||
| <span style="position: relative" class="fr mr20"> | <span style="position: relative" class="fr mr20"> | ||||
| <%= link_to( | <%= link_to( | ||||
| @@ -1,5 +1,10 @@ | |||||
| <ul> | <ul> | ||||
| <% comments.each do |comment| %> | <% 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"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| showNormalImage('reply_content_<%= comment.id %>'); | showNormalImage('reply_content_<%= comment.id %>'); | ||||
| @@ -56,7 +61,7 @@ | |||||
| :title => l(:button_reply)) %> | :title => l(:button_reply)) %> | ||||
| <span id="reply_iconup_<%= comment.id %>" class="reply_iconup02" style="display: none"> ︿</span> | <span id="reply_iconup_<%= comment.id %>" class="reply_iconup02" style="display: none"> ︿</span> | ||||
| </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}, | <%= 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)) %> | :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' %> | <% elsif type == 'Issue' %> | ||||
| @@ -81,12 +81,18 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| </div> | </div> | ||||
| <%# 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 %> | |||||
| <div class="homepagePostReply"> | <div class="homepagePostReply"> | ||||
| <div id="activity_post_reply_<%=user_activity_id %>"> | <div id="activity_post_reply_<%=user_activity_id %>"> | ||||
| <%=render :partial => 'users/course_message_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | <%=render :partial => 'users/course_message_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | ||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| user_card_show_hide(); | user_card_show_hide(); | ||||
| @@ -41,13 +41,16 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| </div> | </div> | ||||
| <%# all_comments = []%> | |||||
| <%# 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"> | <div class="homepagePostReply"> | ||||
| <div id="activity_post_reply_<%=user_activity_id %>"> | <div id="activity_post_reply_<%=user_activity_id %>"> | ||||
| <%=render :partial => 'users/user_blog_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | <%=render :partial => 'users/user_blog_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | ||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $("#moreProject_<%=user_activity_id %>").click(function(){ | $("#moreProject_<%=user_activity_id %>").click(function(){ | ||||
| $("#relatePWrap_<%=user_activity_id %>").toggleClass('relatePWrap'); | $("#relatePWrap_<%=user_activity_id %>").toggleClass('relatePWrap'); | ||||
| @@ -62,13 +62,16 @@ | |||||
| </div> | </div> | ||||
| <div class="cl"></div> | <div class="cl"></div> | ||||
| </div> | </div> | ||||
| <%# 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"> | <div class="homepagePostReply"> | ||||
| <div id="activity_post_reply_<%=user_activity_id %>"> | <div id="activity_post_reply_<%=user_activity_id %>"> | ||||
| <%=render :partial => 'users/user_journal_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | <%=render :partial => 'users/user_journal_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> | ||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||
| $(function(){ | $(function(){ | ||||
| user_card_show_hide(); | user_card_show_hide(); | ||||
| @@ -12,7 +12,8 @@ RedmineApp::Application.configure do | |||||
| # Show full error reports and disable caching | # Show full error reports and disable caching | ||||
| config.consider_all_requests_local = true | config.consider_all_requests_local = true | ||||
| config.action_controller.perform_caching = true | config.action_controller.perform_caching = true | ||||
| config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" | |||||
| # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" | |||||
| config.cache_store = :redis_store, 'redis://127.0.0.1:6379/0/cache'#, { expires_in: 90.minutes } | |||||
| #config.cache_store = :dalli_store | #config.cache_store = :dalli_store | ||||
| # Don't care if the mailer can't send | # Don't care if the mailer can't send | ||||
| config.action_mailer.raise_delivery_errors = true | config.action_mailer.raise_delivery_errors = true | ||||
| @@ -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 | |||||