Verbessere SQL-Abfragen im Produktionsworker: Optimiere die Abfrage für abgeschlossene Produktionen und verbessere die Lesbarkeit der Preisberechnung.
This commit is contained in:
@@ -8,6 +8,7 @@ pub const QUERY_GET_MONEY: &str = r#"
|
||||
SELECT money FROM falukant_data.falukant_user WHERE id = $1;
|
||||
"#;
|
||||
|
||||
|
||||
pub const QUERY_GET_RANDOM_USER: &str = r#"
|
||||
SELECT id FROM falukant_data.falukant_user ORDER BY RANDOM() LIMIT 1;
|
||||
"#;
|
||||
@@ -1360,26 +1361,22 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
p.quantity,
|
||||
p.start_timestamp,
|
||||
pr.production_time,
|
||||
-- Aggregierte Qualitätsbewertung pro Produktion inkl. Wettereinfluss
|
||||
MAX(
|
||||
GREATEST(
|
||||
0,
|
||||
LEAST(
|
||||
100,
|
||||
MAX(
|
||||
GREATEST(
|
||||
0,
|
||||
LEAST(
|
||||
100,
|
||||
br.region_id,
|
||||
br.falukant_user_id,
|
||||
ROUND(
|
||||
GREATEST(
|
||||
0,
|
||||
LEAST(
|
||||
100,
|
||||
(
|
||||
COALESCE(k.knowledge, 0) + COALESCE(k2.knowledge, 0)
|
||||
)::numeric
|
||||
+ COALESCE(pwe.quality_effect, 0) * 2.5
|
||||
COALESCE(k.knowledge, 0) * 0.6
|
||||
+ COALESCE(k2.knowledge, 0) * 0.3
|
||||
+ COALESCE(pwe.worth_percent, 100) * 0.1
|
||||
)
|
||||
)
|
||||
)::int
|
||||
) AS quality,
|
||||
)
|
||||
)::int AS quality
|
||||
FROM falukant_data.production p
|
||||
JOIN falukant_type.product pr
|
||||
ON p.product_id = pr.id
|
||||
JOIN falukant_data.branch br
|
||||
@@ -1389,27 +1386,15 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
JOIN falukant_data.knowledge k
|
||||
ON p.product_id = k.product_id
|
||||
AND k.character_id = c.id
|
||||
JOIN falukant_data.stock s
|
||||
ON s.branch_id = br.id
|
||||
-- Optionaler Wettereinfluss: pro (Produkt, Wetter) genau ein Datensatz
|
||||
LEFT JOIN falukant_type.product_weather_effect pwe
|
||||
ON pwe.product_id = p.product_id
|
||||
AND pwe.weather_type_id = p.weather_type_id
|
||||
LEFT JOIN falukant_data.director d
|
||||
ON d.employer_user_id = c.user_id
|
||||
LEFT JOIN falukant_data.knowledge k2
|
||||
ON k2.character_id = d.director_character_id
|
||||
AND k2.product_id = p.product_id
|
||||
LEFT JOIN falukant_type.product_weather_effect pwe
|
||||
ON pwe.product_id = p.product_id
|
||||
AND pwe.weather_type_id = p.weather_type_id
|
||||
WHERE p.start_timestamp + INTERVAL '1 minute' * pr.production_time <= NOW()
|
||||
GROUP BY
|
||||
p.id,
|
||||
p.branch_id,
|
||||
p.product_id,
|
||||
p.quantity,
|
||||
p.start_timestamp,
|
||||
pr.production_time,
|
||||
br.region_id,
|
||||
br.falukant_user_id
|
||||
ORDER BY p.start_timestamp;
|
||||
"#;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user