[Dancer-users] Dancer::Plugin::DBIC, plackup, and database connections

Brian E. Lozier brian at massassi.com
Fri May 20 16:48:57 CEST 2011

I have written my app so far only in a "development" environment.
I've just added some time zone handling and I'm worried I've
programmed it such that different users can stomp on eachother's time
zone.  First, here is how it works currently:

Detect user's time zone using javascript during registration (using
https://bitbucket.org/pellepim/jstimezonedetect/wiki/Home ) and store
it in the database.  Please note that I don't care  the timezone is
exactly right, I just want to show reasonable dates/times by default.
I might let them explicitly choose a time zone at some point in the
future but that's not really what this question is about.

When a user logs in I pull the tz info from the database and put it in
their session.

In a "before" handler I pull a database handle (dbh) from
Dancer::Plugin::DBIC and set the session time zone like this:

        my $dbh = schema->storage->dbh();

        $dbh->do("SET SESSION TIME ZONE ?", {}, $tz) or die("..some error...");

I'm currently running my application with plackup and then I have a
nginx in front of that.  The nginx serves all the "public" files
(images, css) and then proxies to the actual web app for everything

The problem is that I don't fully understand (or know where to find
information on) the way Dancer::Plugin::DBIC and thus DBIC itself
connects to the database.  I'm wondering if the connections are
persistent at all or if a new connection is created on each and every
request.  I've got a lot of experience with mod_perl and I've used
Apache::DBI which pools connections and ensures that a handle isn't
shared by multiple requests at the same time.

I want to avoid a case where one user sets the time zone on the
database session and then another user overwrites it.  This should not
happen if the connections are created on each request (but that can
cause performance issues and I need to figure a way to have persistent
connections) and it should also not matter if the db handle is dealt
with similar to Apache::DBI.

Thanks for any insight,

More information about the Dancer-users mailing list