From 6c76cacb61768fbee43241d7c81a9a37d591ef30 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 27 Jan 2015 15:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=A1=B9=E7=9B=AE=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=BE=88=E6=85=A2=EF=BC=8C=E6=95=B0=E6=8D=AE=E9=87=8F?= =?UTF-8?q?=E5=BE=88=E5=A4=A7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/acts_as_activity_provider.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb index b7cb8c17d..a4f0ac21d 100644 --- a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb +++ b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb @@ -49,11 +49,8 @@ module Redmine end module ClassMethods - # Time 2015-01-27 13:37:41 - # Author lizanle - # Description 应该保持原来的写法更加容易懂 # Returns events of type event_type visible by user that occured between from and to - def find_events(event_type, user, from, to, options) + def find_events(event_type, user, days, created_time, options) provider_options = activity_provider_options[event_type] raise "#{self.name} can not provide #{event_type} events." if provider_options.nil? @@ -94,23 +91,19 @@ module Redmine ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option." scope = scope.scoped(:conditions => Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) end - # Time 2015-01-27 13:34:40 + # Time 2015-01-27 15:18:33 # Author lizanle - # Description 这段代码就用scope.all进行了查询,拖慢了速度,并且增加了时间跨度,时间跨度应该由管理员来调整,所以应该去掉 -=begin - unless scope.all(provider_options[:find_options].dup).first.nil? + # Description 删除 unless scope.all,因为这个执行查询,并且没有加入时间限制,与下边 scope.all(provider_options[:find_options].dup)的重复查询 + if options[:course] if provider_options[:timestamp].include? "updated_on" to = scope.scoped(:order => "#{provider_options[:timestamp]} desc").all(provider_options[:find_options].dup).first.updated_on else to = scope.scoped(:order => "#{provider_options[:timestamp]} desc").all(provider_options[:find_options].dup).first.created_on end - if options[:course] from = (to - days.days) > created_time ? (to - days.days) : created_time.to_date - else - from = to - days.day - 1.years - end + else + from = to - Setting.activity_days_default.to_i end -=end if from && to scope = scope.scoped(:conditions => ["#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to])