Add SQLx operation tracing (#5223)

* wip: vendor sqlx-tracing

* (compiles) standardize pg types used

* more standardization

* general log message improvements

* wip: improve sqlx-tracing architecture

* unify sqlx::Executor type

* wip: try fix sqlx tracing

* wip: sqlx-tracing compiles

* so close

* it compiles

* fix ci
This commit is contained in:
aecsocket
2026-01-28 13:38:57 +00:00
committed by GitHub
parent 7cb7e881fa
commit e57c15b3ce
146 changed files with 7320 additions and 801 deletions
+7 -7
View File
@@ -1,7 +1,7 @@
use crate::database::PgPool;
use chrono::{Datelike, Duration, TimeZone, Utc};
use eyre::{Context, Result, eyre};
use rust_decimal::{Decimal, dec};
use sqlx::PgPool;
use tracing::warn;
use crate::database::models::{DBAffiliateCodeId, DBUserId};
@@ -58,7 +58,7 @@ pub async fn process_affiliate_payouts(postgres: &PgPool) -> Result<()> {
)
"#
)
.fetch_all(&mut *txn)
.fetch_all(&mut txn)
.await
.wrap_err("failed to fetch charges awaiting affiliate payout")?;
@@ -147,7 +147,7 @@ pub async fn process_affiliate_payouts(postgres: &PgPool) -> Result<()> {
available,
affiliate_code_id as _,
)
.fetch_one(&mut *txn)
.fetch_one(&mut txn)
.await
.wrap_err_with(|| eyre!("failed to insert payout value for ({affiliate_user_id:?}, {affiliate_code_id:?})"))?
.id;
@@ -170,7 +170,7 @@ pub async fn process_affiliate_payouts(postgres: &PgPool) -> Result<()> {
&insert_usap_affiliate_codes[..],
&insert_usap_payout_values[..],
)
.execute(&mut *txn)
.execute(&mut txn)
.await
.wrap_err("failed to associate charges with affiliate payouts")?;
@@ -221,7 +221,7 @@ pub async fn remove_payouts_for_refunded_charges(
AND refund_charges.charge_type = 'refund'
"#
)
.fetch_all(&mut *txn)
.fetch_all(&mut txn)
.await
.wrap_err("failed to fetch refundable affiliate payouts")?;
@@ -248,7 +248,7 @@ pub async fn remove_payouts_for_refunded_charges(
",
&usap_ids[..]
)
.execute(&mut *txn)
.execute(&mut txn)
.await
.wrap_err("failed to delete affiliate payout associations")?;
@@ -260,7 +260,7 @@ pub async fn remove_payouts_for_refunded_charges(
",
&payout_value_ids[..]
)
.execute(&mut *txn)
.execute(&mut txn)
.await
.wrap_err("failed to delete payout values")?;
+4 -2
View File
@@ -4,7 +4,6 @@
use eyre::eyre;
use modrinth_util::decimal::Decimal2dp;
use rust_decimal::Decimal;
use sqlx::PgTransaction;
use thiserror::Error;
pub mod mural;
@@ -12,7 +11,10 @@ pub mod paypal;
pub mod tremendous;
use crate::{
database::models::{DBPayoutId, DBUser},
database::{
PgTransaction,
models::{DBPayoutId, DBUser},
},
models::payouts::{PayoutMethodRequest, Withdrawal},
queue::payouts::PayoutsQueue,
routes::ApiError,
+10 -10
View File
@@ -1,6 +1,7 @@
use crate::database::models::notification_item::NotificationBuilder;
use crate::database::models::payouts_values_notifications;
use crate::database::redis::RedisPool;
use crate::database::{PgPool, PgTransaction};
use crate::models::payouts::{
PayoutDecimal, PayoutInterval, PayoutMethod, PayoutMethodType,
TremendousForexResponse,
@@ -26,7 +27,6 @@ use rust_decimal::prelude::ToPrimitive;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::PgPool;
use sqlx::postgres::PgQueryResult;
use std::collections::HashMap;
use tokio::sync::RwLock;
@@ -1023,7 +1023,7 @@ pub async fn process_payout(
.map(|x| x.to_string())
.collect::<Vec<String>>(),
)
.fetch(&mut *transaction)
.fetch(&mut transaction)
.try_fold(DashMap::new(), |acc: DashMap<i64, HashMap<i64, Decimal>>, r| {
acc.entry(r.id)
.or_default()
@@ -1046,7 +1046,7 @@ pub async fn process_payout(
.map(|x| x.to_string())
.collect::<Vec<String>>(),
)
.fetch(&mut *transaction)
.fetch(&mut transaction)
.try_fold(
DashMap::new(),
|acc: DashMap<i64, HashMap<i64, Decimal>>, r| {
@@ -1193,7 +1193,7 @@ pub async fn process_payout(
&insert_starts[..],
&insert_availables[..]
)
.execute(&mut *transaction)
.execute(&mut transaction)
.await?;
transaction.commit().await?;
@@ -1208,7 +1208,7 @@ pub async fn insert_payouts(
insert_payouts: Vec<Decimal>,
insert_starts: Vec<DateTime<Utc>>,
insert_availables: Vec<DateTime<Utc>>,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
transaction: &mut PgTransaction<'_>,
) -> sqlx::Result<PgQueryResult> {
sqlx::query!(
"
@@ -1221,7 +1221,7 @@ pub async fn insert_payouts(
&insert_starts[..],
&insert_availables[..],
)
.execute(&mut **transaction)
.execute(&mut *transaction)
.await
}
@@ -1234,11 +1234,11 @@ pub async fn index_payouts_notifications(
let mut transaction = pool.begin().await?;
payouts_values_notifications::synchronize_future_payout_values(
&mut *transaction,
&mut transaction,
200,
)
.await?;
let items = payouts_values_notifications::PayoutsValuesNotification::unnotified_users_with_available_payouts_with_limit(&mut *transaction, 200).await?;
let items = payouts_values_notifications::PayoutsValuesNotification::unnotified_users_with_available_payouts_with_limit(&mut transaction, 200).await?;
let payout_ref_ids = items.iter().map(|x| x.id).collect::<Vec<_>>();
let dates_available =
@@ -1254,7 +1254,7 @@ pub async fn index_payouts_notifications(
.await?;
payouts_values_notifications::PayoutsValuesNotification::set_notified_many(
&payout_ref_ids,
&mut *transaction,
&mut transaction,
)
.await?;
@@ -1320,7 +1320,7 @@ pub async fn insert_bank_balances_and_webhook(
&insert_pending[..],
&insert_recorded[..],
)
.fetch_one(&mut *transaction)
.fetch_one(&mut transaction)
.await?;
if inserted {
+4 -4
View File
@@ -1,10 +1,10 @@
use crate::database::PgPool;
use chrono::Utc;
use eyre::{Result, eyre};
use futures::{StreamExt, TryFutureExt, stream::FuturesUnordered};
use modrinth_util::decimal::Decimal2dp;
use rust_decimal::{Decimal, prelude::ToPrimitive};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use tracing::{info, trace, warn};
use crate::{
@@ -177,7 +177,7 @@ pub async fn sync_pending_payouts_from_mural(
.collect::<Vec<String>>(),
i64::from(limit),
)
.fetch_all(&mut *txn)
.fetch_all(&mut txn)
.await
.wrap_internal_err("failed to fetch incomplete Mural payouts")?;
@@ -235,7 +235,7 @@ pub async fn sync_pending_payouts_from_mural(
&payout_ids,
&payout_statuses,
)
.execute(&mut *txn)
.execute(&mut txn)
.await
.wrap_internal_err("failed to update payout statuses")?;
@@ -452,7 +452,7 @@ mod tests {
}
async fn setup_test_db_with_payouts(
db: &sqlx::PgPool,
db: &PgPool,
payouts: Vec<(i64, String, PayoutStatus)>,
) -> Result<(), eyre::Error> {
for (id, platform_id, status) in payouts {