[Catalyst] Duplicate entries with
C::P::Session::Store::DBIC and MySQL
Tobias Kremer
list at funkreich.de
Mon Aug 4 13:22:01 BST 2008
On 29 Jul 2008, at 12:30, Tobias Kremer wrote:
> The short time window between the find() and create() calls of the
> find_or_create() method indeed is the problem. It sounds like this
> window should be too small to ever happen but in reality it happens very
> often in our (and other's) applications. I can force the problem by
> hammering reload in my browser.
Because the duplicate entry errors are multiplying like crazy, I'm in a
desperate need for a quick fix. So, until we fix DBIC's find_or_create()
method, I'm thinking about adding the following snippet to MyApp.pm after
setup():
*{Catalyst::Plugin::Session::Store::DBIC::Delegate::flash} = sub {
my ($self, $key) = @_;
my $row = $self->_flash_row;
unless ($row) {
eval {
$row = $self->model->create({ $self->id_field => $key });
};
if( $@ ) {
die $@ unless $@ =~ /Duplicate entry/;
$row = $self->model->find({ $self->id_field => $key });
}
$self->_flash_row($row);
}
return $row;
};
Because I really don't like poking around in the symbol table and I'm completely
unsure what side-effects this may cause, I'd like to ask for your comments on
this. Could this be a quick-hack-remedy for the problem at hand or will this
screw things up big-time?
Thanks!
--Tobias
More information about the Catalyst
mailing list