put hit register into transaction

This commit is contained in:
Joe Ardent 2024-03-28 19:10:44 -07:00
parent a2c466f5ac
commit bc05fe87b3
1 changed files with 9 additions and 4 deletions

View File

@ -73,10 +73,15 @@ async fn register_hit(
let key = format!("{now}{host}{slug}{salt}").into_bytes();
let key = hex::encode(shasum(&key));
sqlx::query!("insert into hits (page, hit_key) values (?, ?)", slug, key,)
.execute(&db)
.await
.unwrap_or_default();
let tx = db.begin().await;
if let Ok(mut tx) = tx {
sqlx::query!("insert into hits (page, hit_key) values (?, ?)", slug, key,)
.execute(&mut *tx)
.await
.unwrap_or_default();
tx.commit().await.unwrap_or_default();
}
"".to_string()
}