Hiya Bill.
long time no see!
I would certainly agree with Rob here.
What you will see in the sql logs is multiple queries being made for the author and books in both cases. Grails defaults to lazy loading collections, and so at the statement
def author= Author.findByName(params.id)
You have only loaded the author, not the books.
Adding an extra statement to load the books in the normal paginated way will be more efficient, and more maintainable, as it is cleaner and more obvious what it is doing.
This is the style I normally employ to get this kind of data.
def timeline = {
println "timeline[" + params+ "]"
if (params.id) {
def author= Author.findByName(params.id)
def books = Book.withCriteria {
eq('author', author)
firstResult(5)
maxResults(10)
}
def totalBooks = Book.createCriteria().count {
eq(author, author)
}
...
}
Also, (not sure on this), but the size() statement on the books collection will trigger a count query, but may also trigger other queries too, so it pays when you have such a large data set to be specific in what you get GORM to do.
(updated as per Bills comment below)