From e2b5365810bd49c799b396a98cbb07b54a86f475 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Mon, 12 Aug 2024 18:08:41 +0200 Subject: database: avoid needlessly incrementing backends.id --- lib/Travelynx/Command/database.pm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm index 4389430..ebe9537 100644 --- a/lib/Travelynx/Command/database.pm +++ b/lib/Travelynx/Command/database.pm @@ -2815,17 +2815,27 @@ sub sync_stations { sub sync_backends { my ($db) = @_; for my $service ( Travel::Status::DE::HAFAS::get_services() ) { - $db->insert( + my $present = $db->select( 'backends', + 'count(*) as count', { - iris => 0, hafas => 1, - efa => 0, - ris => 0, - name => $service->{shortname}, - }, - { on_conflict => undef } - ); + name => $service->{shortname} + } + )->hash->{count}; + if ( not $present ) { + $db->insert( + 'backends', + { + iris => 0, + hafas => 1, + efa => 0, + ris => 0, + name => $service->{shortname}, + }, + { on_conflict => undef } + ); + } } $db->update( 'schema_version', -- cgit v1.2.3