SQL optimisation

This commit is contained in:
Meutel 2015-08-15 15:51:02 +02:00
parent cbf7c6d58e
commit d08fb8c456
2 changed files with 2 additions and 8 deletions

View File

@ -44,13 +44,7 @@ class AuthorsController < ApplicationController
end end
def authors def authors
@author = Author.find(params[:id]) @authors = Author.find_by_sql(["select distinct a.* from books_authors_link bal1 left outer join books_authors_link bal2 on bal1.book = bal2.book left outer join authors a on a.id = bal2.author where bal1.author = ? and bal2. author != ?", params[:id], params[:id]])
@authors = Array.new
@author.books.each do |b|
@authors.concat b.authors
end
@authors.uniq!
@authors.select! {|a| a != @author}
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js

View File

@ -10,7 +10,7 @@ class BooksController < ApplicationController
end end
def index def index
@books = Book .where(query_filter(Book.table_name)) @books = Book.where(query_filter(Book.table_name))
.includes(:authors, :serie) .references(:authors, :serie) .includes(:authors, :serie) .references(:authors, :serie)
.order(sort_col) .order(sort_col)
.paginate(pagination) .paginate(pagination)