summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-02 22:13:11 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-02 22:13:11 +0000
commit013c6fe009e74892659c64c2936a2668a9663985 (patch)
tree4aa377824757ac946092d10b625d71bde7e0cb25
parent30787e9cd215e0d2932f0678018081051f95e70c (diff)
downloadredmine-013c6fe009e74892659c64c2936a2668a9663985.tar.gz
redmine-013c6fe009e74892659c64c2936a2668a9663985.zip
Replaces find(:all) calls in acts_as_searchable.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10927 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
index fe0f8518e..dc8d1bdcc 100644
--- a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
+++ b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
@@ -72,14 +72,8 @@ module Redmine
tokens = [] << tokens unless tokens.is_a?(Array)
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
- find_options = {:include => searchable_options[:include]}
- find_options[:order] = "#{searchable_options[:order_column]} " + (options[:before] ? 'DESC' : 'ASC')
-
limit_options = {}
limit_options[:limit] = options[:limit] if options[:limit]
- if options[:offset]
- limit_options[:conditions] = "(#{searchable_options[:date_column]} " + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
- end
columns = searchable_options[:columns]
columns = columns[0..0] if options[:titles_only]
@@ -98,9 +92,9 @@ module Redmine
sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
- find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
+ tokens_conditions = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
- scope = self
+ scope = self.scoped
project_conditions = []
if searchable_options.has_key?(:permission)
project_conditions << Project.allowed_to_condition(user, searchable_options[:permission] || :view_project)
@@ -117,9 +111,19 @@ module Redmine
results = []
results_count = 0
- scope = scope.scoped({:conditions => project_conditions}).scoped(find_options)
- results_count = scope.count(:all)
- results = scope.find(:all, limit_options)
+ scope = scope.
+ includes(searchable_options[:include]).
+ order("#{searchable_options[:order_column]} " + (options[:before] ? 'DESC' : 'ASC')).
+ where(project_conditions).
+ where(tokens_conditions)
+
+ results_count = scope.count
+
+ scope_with_limit = scope.limit(options[:limit])
+ if options[:offset]
+ scope_with_limit = scope_with_limit.where("#{searchable_options[:date_column]} #{options[:before] ? '<' : '>'} ?", options[:offset])
+ end
+ results = scope_with_limit.all
[results, results_count]
end