| | 78 | }; |
| | 79 | |
| | 80 | # DBIx::Class's find_or_create is incredibly stupid and allows for race |
| | 81 | # conditions with critical code like this. |
| | 82 | # This is MySQL-specific! Also it is a horrendous hack. |
| | 83 | # CAVEAT EMPTOR: may break if you upgrade |
| | 84 | *{'Catalyst::Plugin::Session::Store::DBIC::Delegate::session'} = sub { |
| | 85 | my ($self, $key) = @_; |
| | 86 | |
| | 87 | my $row = $self->_session_row; |
| | 88 | |
| | 89 | unless ($row) { |
| | 90 | eval { |
| | 91 | $row = $self->model->find_or_create({ $self->id_field => $key }); |
| | 92 | } |
| | 93 | if ($@ and $@ =~ /Duplicate entry/) { |
| | 94 | $row = $self->model->create({ $self->id_field => $key }); |
| | 95 | } else { |
| | 96 | die $@; |
| | 97 | } |
| | 98 | $self->_session_row($row); |
| | 99 | } |
| | 100 | |
| | 101 | return $row; |