fix: store and get submission ID
DESCRIPTION If the same survey_user submits the survey many times, their first submission ID was being used to record benchmarks from their future submissions. Which resulted in submissions with empty benchmarks. This patch gets the submission ID as the record is being created and records benches using that. Bug fix and one less query.
This commit is contained in:
parent
e9709ed744
commit
c576487333
1 changed files with 8 additions and 23 deletions
|
@ -215,43 +215,29 @@ async fn submit(
|
||||||
let user_id = Uuid::from_str(&username).unwrap();
|
let user_id = Uuid::from_str(&username).unwrap();
|
||||||
let payload = payload.into_inner();
|
let payload = payload.into_inner();
|
||||||
|
|
||||||
sqlx::query!(
|
struct ID {
|
||||||
|
id: i32,
|
||||||
|
}
|
||||||
|
let resp_id = sqlx::query_as!(
|
||||||
|
ID,
|
||||||
"INSERT INTO survey_responses (
|
"INSERT INTO survey_responses (
|
||||||
user_id,
|
user_id,
|
||||||
campaign_id,
|
campaign_id,
|
||||||
device_user_provided,
|
device_user_provided,
|
||||||
device_software_recognised,
|
device_software_recognised,
|
||||||
threads
|
threads
|
||||||
) VALUES ($1, $2, $3, $4, $5);",
|
) VALUES ($1, $2, $3, $4, $5)
|
||||||
|
RETURNING ID;",
|
||||||
&user_id,
|
&user_id,
|
||||||
&campaign_id,
|
&campaign_id,
|
||||||
&payload.device_user_provided,
|
&payload.device_user_provided,
|
||||||
&payload.device_software_recognised,
|
&payload.device_software_recognised,
|
||||||
&payload.threads
|
&payload.threads
|
||||||
)
|
)
|
||||||
.execute(&data.db)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
struct ID {
|
|
||||||
id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
let resp_id = sqlx::query_as!(
|
|
||||||
ID,
|
|
||||||
"SELECT ID
|
|
||||||
FROM survey_responses
|
|
||||||
WHERE
|
|
||||||
user_id = $1
|
|
||||||
AND
|
|
||||||
device_software_recognised = $2;",
|
|
||||||
&user_id,
|
|
||||||
&payload.device_software_recognised
|
|
||||||
)
|
|
||||||
.fetch_one(&data.db)
|
.fetch_one(&data.db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut futs = Vec::with_capacity(payload.benches.len());
|
let mut futs = Vec::with_capacity(payload.benches.len());
|
||||||
|
|
||||||
for bench in payload.benches.iter() {
|
for bench in payload.benches.iter() {
|
||||||
let fut = sqlx::query!(
|
let fut = sqlx::query!(
|
||||||
"INSERT INTO survey_benches
|
"INSERT INTO survey_benches
|
||||||
|
@ -261,8 +247,7 @@ async fn submit(
|
||||||
&bench.difficulty,
|
&bench.difficulty,
|
||||||
bench.duration
|
bench.duration
|
||||||
)
|
)
|
||||||
.execute(&data.db);
|
.execute(&data.db); //.await?;
|
||||||
|
|
||||||
futs.push(fut);
|
futs.push(fut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue