On Wed, Jun 20, 2012 at 02:49:56PM -0400, Len Jaffe wrote:
> On Wed, Jun 20, 2012 at 2:39 PM, Bill Moseley <[email protected]> wrote:
> > I'd worry less about where your database calls are happening.  Do you
> > really care if [% user.address.city | html %] hits the database in the
> > template or in the controller?
> > ... 
> > One point of the object abstraction is you don't care about the
> > implementation.   The real problem I've seen, though, is doing something
> > stupid like huge nested loops in the template where each one generates a
> > query.
> This is what I meant to about maintenance nightmare.
> I've inherited apps like this where I had to roll nested queries (in
> templates) up into a single query to go from 120 round-trips to the
> database, taking 8 seconds, into one round trip, taking half a second.

Making sure you don't hit the database from the templating layer doesn't
magically make this problem go away.  I recently fixed an application
where we were making over a thousand queries *in a single subroutine*
where one would do the job.

I did it by using prefetch.  That one line I added would have the same
effect regardless of whether the loop was in the same subroutine or a
mile away in a template.

-- 
David Cantrell | top google result for "topless karaoke murders"

  The test of the goodness of a thing is its fitness for use.  If it
  fails on this first test, no amount of ornamentation or finish will
  make it any better, it will only make it more expensive and foolish.
     -- Frank Pick, lecture to the Design and Industries Assoc, 1916

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to