Refactor product cost retrieval in DirectorWorker: Simplify the SQL query by removing the original_sell_cost from the selection, and adjust the cost resolution logic to improve clarity and efficiency in database interactions.

This commit is contained in:
Torsten Schulz (local)
2026-01-28 14:41:27 +01:00
parent c9e0781b61
commit 1d9a7ba8a0
3 changed files with 3 additions and 9 deletions

View File

@@ -720,12 +720,6 @@ impl DirectorWorker {
fn resolve_one_piece_cost(conn: &mut DbConnection, product_id: i32, fallback: f64) -> Result<f64, DbError> {
conn.prepare("get_product_cost", QUERY_GET_PRODUCT_COST)?;
let rows = conn.execute("get_product_cost", &[&product_id])?;
if let Some(row) = rows.first()
&& let Some(osc) = row.get("original_sell_cost")
&& let Ok(v) = osc.parse::<f64>()
{
return Ok(v);
}
if let Some(row) = rows.first()
&& let Some(sc) = row.get("sell_cost")
&& let Ok(v) = sc.parse::<f64>()

View File

@@ -44,7 +44,7 @@ VALUES ($1, $2, FALSE, NOW(), NOW());
// Product pricing
pub const QUERY_GET_PRODUCT_COST: &str = r#"
SELECT original_sell_cost, sell_cost FROM falukant_type.product WHERE id = $1;
SELECT sell_cost FROM falukant_type.product WHERE id = $1;
"#;
pub const QUERY_GET_DIRECTORS: &str = r#"