diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-12-12 20:49:31 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-12-12 20:49:31 +0000 |
commit | 2fe806a4a49cc3fcd7c2b7fe3a385d3a46ffbfd5 (patch) | |
tree | 82f8da72bfdc6e68c83cbecf3ffac2b5bcc9738a /test/unit/search_test.rb | |
parent | 963719042a12e7833a95396036a662237a7939a0 (diff) | |
download | redmine-2fe806a4a49cc3fcd7c2b7fe3a385d3a46ffbfd5.tar.gz redmine-2fe806a4a49cc3fcd7c2b7fe3a385d3a46ffbfd5.zip |
Rewrites search engine to properly paginate results (#18631).
Instead of counting and retrieving results based on their timestamps, we now load all result ids then load the appropriate results by their ids. This also brings a 2x performance improvement as we search tokens in one of the 2 queries only.
git-svn-id: http://svn.redmine.org/redmine/trunk@13739 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/search_test.rb')
-rw-r--r-- | test/unit/search_test.rb | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/test/unit/search_test.rb b/test/unit/search_test.rb index 5a10ec71c..c98982e8a 100644 --- a/test/unit/search_test.rb +++ b/test/unit/search_test.rb @@ -42,25 +42,25 @@ class SearchTest < ActiveSupport::TestCase def test_search_by_anonymous User.current = nil - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert r.include?(@changeset) # Removes the :view_changesets permission from Anonymous role remove_permission Role.anonymous, :view_changesets User.current = nil - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert !r.include?(@changeset) # Make the project private @project.update_attribute :is_public, false - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert !r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert !r.include?(@changeset) end @@ -68,25 +68,25 @@ class SearchTest < ActiveSupport::TestCase User.current = User.find_by_login('rhill') assert User.current.memberships.empty? - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert r.include?(@changeset) # Removes the :view_changesets permission from Non member role remove_permission Role.non_member, :view_changesets User.current = User.find_by_login('rhill') - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert !r.include?(@changeset) # Make the project private @project.update_attribute :is_public, false - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert !r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert !r.include?(@changeset) end @@ -94,16 +94,16 @@ class SearchTest < ActiveSupport::TestCase User.current = User.find_by_login('jsmith') assert User.current.projects.include?(@project) - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert r.include?(@changeset) # Make the project private @project.update_attribute :is_public, false - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert r.include?(@changeset) end @@ -115,26 +115,26 @@ class SearchTest < ActiveSupport::TestCase User.current = User.find_by_login('jsmith') assert User.current.projects.include?(@project) - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert !r.include?(@changeset) # Make the project private @project.update_attribute :is_public, false - r = Issue.search(@issue_keyword).first + r = Issue.search_results(@issue_keyword) assert r.include?(@issue) - r = Changeset.search(@changeset_keyword).first + r = Changeset.search_results(@changeset_keyword) assert !r.include?(@changeset) end def test_search_issue_with_multiple_hits_in_journals - i = Issue.find(1) - assert_equal 2, i.journals.where("notes LIKE '%notes%'").count + issue = Issue.find(1) + assert_equal 2, issue.journals.where("notes LIKE '%notes%'").count - r = Issue.search('%notes%').first + r = Issue.search_results('%notes%') assert_equal 1, r.size - assert_equal i, r.first + assert_equal issue, r.first end private |