[Catalyst] Session duplicate key constraints on concurrent
requests
Tobias Kremer
tobias.kremer at gmail.com
Fri Oct 7 20:22:07 GMT 2011
Hi Janne,
I appreciate your taking the time to look into this. Unfortunately your patches are for the Store::DBI backend, whereas I'm using Store::DBIC (DBIx::Class). The INSERT IGNORE solution is probably exactly what this case needs, but as you said, it's MySQL-specific and thus not suitable for the masses.
I suppose to really solve this for most databases, we'd first need a portable way to check if a database error is a duplicate key constraint error. This should probably be abstracted away in DBIx::Class.
Here's hoping that somebody comes up with a simpler solution ... My only alternative right now would be switching to a Memcached session backend.
--Toby
On 07.10.2011, at 21:25, Janne Snabb wrote:
> On Fri, 7 Oct 2011, Janne Snabb wrote:
>
>> Something like this perhaps? Untested code.
>
> Sorry about flooding. This is another much simpler solution but works
> only on MySQL. I think there is no standard SQL syntax to accomplish
> the same without extra DB fields.
>
> --
> Janne Snabb / EPIPE Communications
> snabb at epipe.com - http://epipe.com/
>
>
> diff -U5 -r Catalyst-Plugin-Session-Store-DBI-0.16/lib/Catalyst/Plugin/Session/Store/DBI.pm Catalyst-Plugin-Session-Store-DBI-0.16+otherpatch/lib/Catalyst/Plugin/Session/Store/DBI.pm
> --- Catalyst-Plugin-Session-Store-DBI-0.16/lib/Catalyst/Plugin/Session/Store/DBI.pm 2010-03-24 04:47:13.000000000 +0700
> +++ Catalyst-Plugin-Session-Store-DBI-0.16+otherpatch/lib/Catalyst/Plugin/Session/Store/DBI.pm 2011-10-08 02:21:12.227212244 +0700
> @@ -156,11 +156,11 @@
> check_existing =>
> "SELECT 1 FROM $table WHERE $id_field = ?",
> update_session =>
> "UPDATE $table SET $data_field = ?, $expires_field = ? WHERE $id_field = ?",
> insert_session =>
> - "INSERT INTO $table ($data_field, $expires_field, $id_field) VALUES (?, ?, ?)",
> + "INSERT IGNORE INTO $table ($data_field, $expires_field, $id_field) VALUES (?, ?, ?)",
> update_expires =>
> "UPDATE $table SET $expires_field = ? WHERE $id_field = ?",
> delete_session =>
> "DELETE FROM $table WHERE $id_field = ?",
> delete_expired_sessions =>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
More information about the Catalyst
mailing list