summaryrefslogtreecommitdiff
path: root/lib/Travelynx.pm
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-04-21 19:21:16 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-04-21 19:21:16 +0200
commita0bd8395946f9f944f798c081752bb04db335203 (patch)
treec2be648afddef3fbb403815d78485de6b2d354c5 /lib/Travelynx.pm
parent2ff5f92bcc7b4106a675e2bd01da73f8150dae5f (diff)
refactor polyline insertion into InTransit Model
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-xlib/Travelynx.pm104
1 files changed, 9 insertions, 95 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 6bf9f02..4d04e9e 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -621,52 +621,11 @@ sub startup {
}
if ($polyline) {
- my $coords = $polyline->{coords};
- my $from_eva = $polyline->{from_eva};
- my $to_eva = $polyline->{to_eva};
-
- my $polyline_str = JSON->new->encode($coords);
-
- my $pl_res = $db->select(
- 'polylines',
- ['id'],
- {
- origin_eva => $from_eva,
- destination_eva => $to_eva,
- polyline => $polyline_str
- },
- { limit => 1 }
+ $self->in_transit->set_polyline(
+ uid => $uid,
+ db => $db,
+ polyline => $polyline,
);
-
- my $polyline_id;
- if ( my $h = $pl_res->hash ) {
- $polyline_id = $h->{id};
- }
- else {
- eval {
- $polyline_id = $db->insert(
- 'polylines',
- {
- origin_eva => $from_eva,
- destination_eva => $to_eva,
- polyline => $polyline_str
- },
- { returning => 'id' }
- )->hash->{id};
- };
- if ($@) {
- $self->log->warn(
- "add_route_timestamps: insert polyline: $@"
- );
- }
- }
- if ($polyline_id) {
- $self->in_transit->set_polyline_id(
- uid => $uid,
- db => $db,
- polyline_id => $polyline_id
- );
- }
}
# mustn't be called during a transaction
@@ -1372,57 +1331,12 @@ sub startup {
);
if ($polyline) {
- my $coords = $polyline->{coords};
- my $from_eva = $polyline->{from_eva};
- my $to_eva = $polyline->{to_eva};
-
- my $polyline_str = JSON->new->encode($coords);
-
- my $pl_res = $db->select(
- 'polylines',
- ['id'],
- {
- origin_eva => $from_eva,
- destination_eva => $to_eva,
- polyline => $polyline_str
- },
- { limit => 1 }
+ $self->in_transit->set_polyline(
+ uid => $uid,
+ db => $db,
+ polyline => $polyline,
+ old_id => $in_transit->{polyline_id},
);
-
- my $polyline_id;
- if ( my $h = $pl_res->hash ) {
- $polyline_id = $h->{id};
- }
- else {
- eval {
- $polyline_id = $db->insert(
- 'polylines',
- {
- origin_eva => $from_eva,
- destination_eva => $to_eva,
- polyline => $polyline_str
- },
- { returning => 'id' }
- )->hash->{id};
- };
- if ($@) {
- $self->app->log->warn(
- "add_route_timestamps: insert polyline: $@"
- );
- }
- }
- if (
- $polyline_id
- and ( not $in_transit->{polyline_id}
- or $polyline_id != $in_transit->{polyline_id} )
- )
- {
- $self->in_transit->set_polyline_id(
- uid => $uid,
- db => $db,
- polyline_id => $polyline_id
- );
- }
}
return;