瀏覽代碼

Fix slow query

master
Dylan Baker 8 月之前
父節點
當前提交
e5bc0c6a43
共有 2 個文件被更改,包括 2 次插入3 次删除
  1. 2
    2
      lib/search.rb
  2. 0
    1
      web/server.rb

+ 2
- 2
lib/search.rb 查看文件

57
 def search_threads(q, username, from_date, to_date, sort, offset, exact_match)
57
 def search_threads(q, username, from_date, to_date, sort, offset, exact_match)
58
   sort = Sequel.desc(sort == 'post' ? :last_post_created_at : :created_at)
58
   sort = Sequel.desc(sort == 'post' ? :last_post_created_at : :created_at)
59
   query = VLV::Thread
59
   query = VLV::Thread
60
-    .select(Sequel.lit('threads.*, count(*) OVER() AS full_count'))
60
+    .select(Sequel.lit('threads.*'))
61
     .where(Sequel.lit("(LOWER(threads.creator) = LOWER(?) OR ? = '')", username, username))
61
     .where(Sequel.lit("(LOWER(threads.creator) = LOWER(?) OR ? = '')", username, username))
62
     .where(Sequel.lit("created_at >= ? OR ? IS NULL", from_date, from_date))
62
     .where(Sequel.lit("created_at >= ? OR ? IS NULL", from_date, from_date))
63
     .where(Sequel.lit("created_at >= ? OR ? IS NULL", to_date, to_date))
63
     .where(Sequel.lit("created_at >= ? OR ? IS NULL", to_date, to_date))
74
 
74
 
75
 def search_posts(q, username, from_date, to_date, offset, exact_match)
75
 def search_posts(q, username, from_date, to_date, offset, exact_match)
76
   query = VLV::Post
76
   query = VLV::Post
77
-    .select(Sequel.lit('posts.*, threads.title as thread_title, threads.remote_id as remote_thread_id, count(*) OVER() AS full_count'))
77
+    .select(Sequel.lit('posts.*, threads.title as thread_title, threads.remote_id as remote_thread_id'))
78
     .join(Sequel.lit('threads on posts.thread_id = threads.id'))
78
     .join(Sequel.lit('threads on posts.thread_id = threads.id'))
79
     .where(Sequel.lit("(LOWER(posts.creator) = LOWER(?) OR (? = ''))", username, username))
79
     .where(Sequel.lit("(LOWER(posts.creator) = LOWER(?) OR (? = ''))", username, username))
80
     .where(Sequel.lit("posts.created_at >= ? OR ? IS NULL", from_date, from_date))
80
     .where(Sequel.lit("posts.created_at >= ? OR ? IS NULL", from_date, from_date))

+ 0
- 1
web/server.rb 查看文件

45
       erb :results, { locals: {errors: results[:errors]}, layout: :layout }
45
       erb :results, { locals: {errors: results[:errors]}, layout: :layout }
46
     else
46
     else
47
       params[:current_count] = results[:results].to_a.size
47
       params[:current_count] = results[:results].to_a.size
48
-      params[:full_count] = results[:results].empty? ? 0 : results[:results].first[:full_count]
49
       previous_url, next_url = build_urls(params)
48
       previous_url, next_url = build_urls(params)
50
 
49
 
51
       locals =
50
       locals =

Loading…
取消
儲存