SQL optimisation
This commit is contained in:
parent
cbf7c6d58e
commit
d08fb8c456
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user