summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command/work.pm
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-01-23 17:14:01 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2020-01-23 17:14:01 +0100
commit75363c35cc84f6411fbb73f0c380a41c5e55fdd3 (patch)
treed46ef170d4e05269394bc67e1913c32fc9d71216 /lib/Travelynx/Command/work.pm
parentcda8e53b342ba22d19c8ad5c5b5861159858a9c3 (diff)
work: Fix race condition1.13.6
When a user changes their destination station or checks into a new train while work is updating data for their in_transit entry, values for no longer valid database entrie would be entered.
Diffstat (limited to 'lib/Travelynx/Command/work.pm')
-rw-r--r--lib/Travelynx/Command/work.pm19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm
index fbbf958..405716c 100644
--- a/lib/Travelynx/Command/work.pm
+++ b/lib/Travelynx/Command/work.pm
@@ -47,6 +47,10 @@ sub run {
die("could not find train $train_id at $dep\n");
}
+ # selecting on user_id and train_no avoids a race condition when
+ # a user checks into a new train while we are fetching data for
+ # their previous journey. In this case, the new train would
+ # receive data from the previous journey.
$db->update(
'in_transit',
{
@@ -61,7 +65,10 @@ sub run {
]
),
},
- { user_id => $uid }
+ {
+ user_id => $uid,
+ train_no => $train->train_no
+ }
);
$self->app->add_route_timestamps( $uid, $train, 1 );
}
@@ -102,6 +109,10 @@ sub run {
return;
}
+ # selecting on user_id, train_no and checkout_station_id avoids a
+ # race condition when a user checks into a new train or changes
+ # their destination station while we are fetching times based on no
+ # longer valid database entries.
$db->update(
'in_transit',
{
@@ -117,7 +128,11 @@ sub run {
]
),
},
- { user_id => $uid }
+ {
+ user_id => $uid,
+ train_no => $train->train_no,
+ checkout_station_id => $arr
+ }
);
$self->app->add_route_timestamps( $uid, $train, 0 );
}