Permalink
Browse files

Extend relation to switch "enable_seqscan" around query execution

  • Loading branch information...
1 parent 5f53f5d commit 049c8d42719e4a8af9f2769f9a714d9baaef7b87 @yoshuki committed Nov 2, 2016
Showing with 9 additions and 0 deletions.
  1. +1 −0 app/models/article.rb
  2. +8 −0 app/models/concerns/disable_sequential_scan.rb
@@ -5,6 +5,7 @@ class Article < ApplicationRecord
articles = select("#{quoted_table_name}.*, pgroonga.score(#{quoted_table_name}) AS pgroonga_score")
.where("title #{operator} ? OR body #{operator} ?", query, query)
.reorder('pgroonga_score DESC')
+ .extending(DisableSequentialScan)
return articles unless highlight
@@ -0,0 +1,8 @@
+module DisableSequentialScan
+ def exec_queries
+ @klass.connection.exec_query('SET enable_seqscan TO off')
+ super
+ ensure
+ @klass.connection.exec_query('SET enable_seqscan TO on')
+ end
+end

0 comments on commit 049c8d4

Please sign in to comment.