From d10ecc41fbddc8616ca2beb6a8f54c71ff49a942 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sun, 20 Jun 2021 07:59:26 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E2=80=94=20Avoid=20DB=20conflic?= =?UTF-8?q?ts=20when=20provisioning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cpanfile | 1 + cpanfile.snapshot | 10 +++++----- lib/Lutim/DB/Image/Pg.pm | 7 +++++-- lib/Lutim/DB/Image/SQLite.pm | 7 +++++-- lib/Lutim/Plugin/Helpers.pm | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cpanfile b/cpanfile index 8cd5af3..6c748c1 100644 --- a/cpanfile +++ b/cpanfile @@ -32,6 +32,7 @@ feature 'postgresql', 'PostgreSQL support' => sub { feature 'sqlite', 'SQLite support' => sub { requires 'Mojo::SQLite', '>= 3.000'; requires 'Minion::Backend::SQLite', '>= 4.001'; + requires 'DBD::SQLite', '>= 1.66'; }; feature 'minion', 'Minion support' => sub { requires 'Minion'; diff --git a/cpanfile.snapshot b/cpanfile.snapshot index eb11ab2..b535345 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -294,13 +294,13 @@ DISTRIBUTIONS Test::More 0.88 Time::HiRes 0 version 0 - DBD-SQLite-1.58 - pathname: I/IS/ISHIGAKI/DBD-SQLite-1.58.tar.gz + DBD-SQLite-1.66 + pathname: I/IS/ISHIGAKI/DBD-SQLite-1.66.tar.gz provides: - DBD::SQLite 1.58 + DBD::SQLite 1.66 DBD::SQLite::Constants undef - DBD::SQLite::VirtualTable 1.58 - DBD::SQLite::VirtualTable::Cursor 1.58 + DBD::SQLite::VirtualTable 1.66 + DBD::SQLite::VirtualTable::Cursor 1.66 DBD::SQLite::VirtualTable::FileContent undef DBD::SQLite::VirtualTable::FileContent::Cursor undef DBD::SQLite::VirtualTable::PerlData undef diff --git a/lib/Lutim/DB/Image/Pg.pm b/lib/Lutim/DB/Image/Pg.pm index 9bf2057..c5e2738 100644 --- a/lib/Lutim/DB/Image/Pg.pm +++ b/lib/Lutim/DB/Image/Pg.pm @@ -78,12 +78,15 @@ sub select_empty { } sub write { - my $c = shift; + my $c = shift; + my $provisioning = shift; if ($c->record) { $c->app->pg->db->query('UPDATE lutim SET counter = ?, created_at = ?, created_by = ?, delete_at_day = ?, delete_at_first_view = ?, enabled = ?, filename = ?, footprint = ?, height = ?, last_access_at = ?, mediatype = ?, mod_token = ?, path = ?, short = ?, width = ?, iv = ? WHERE short = ?', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv, $c->short); } else { - $c->app->pg->db->query('INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv); + my $query = 'INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + $query .= ' ON CONFLICT DO NOTHING' if $provisioning; + $c->app->pg->db->query($query, $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv); $c->record(1); } diff --git a/lib/Lutim/DB/Image/SQLite.pm b/lib/Lutim/DB/Image/SQLite.pm index fd68ebc..398e32a 100644 --- a/lib/Lutim/DB/Image/SQLite.pm +++ b/lib/Lutim/DB/Image/SQLite.pm @@ -79,12 +79,15 @@ sub select_empty { } sub write { - my $c = shift; + my $c = shift; + my $provisioning = shift; if ($c->record) { $c->app->sqlite->db->query('UPDATE lutim SET counter = ?, created_at = ?, created_by = ?, delete_at_day = ?, delete_at_first_view = ?, enabled = ?, filename = ?, footprint = ?, height = ?, last_access_at = ?, mediatype = ?, mod_token = ?, path = ?, short = ?, width = ?, iv = ? WHERE short = ?', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv, $c->short); } else { - $c->app->sqlite->db->query('INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv); + my $query = 'INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + $query .= ' ON CONFLICT DO NOTHING' if $provisioning; + $c->app->sqlite->db->query($query, $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv); $c->record(1); } diff --git a/lib/Lutim/Plugin/Helpers.pm b/lib/Lutim/Plugin/Helpers.pm index 3ea009e..040c4c8 100644 --- a/lib/Lutim/Plugin/Helpers.pm +++ b/lib/Lutim/Plugin/Helpers.pm @@ -195,7 +195,7 @@ sub _provisioning { ->delete_at_first_view(0) ->delete_at_day(0) ->mod_token($c->shortener($c->app->config('token_length'))) - ->write; + ->write('provisioning'); $img = Lutim::DB::Image->new(app => $c->app); }