Refactor SQL query for finished productions: Update to use DISTINCT ON for unique production IDs, change JOINs to LEFT JOINs for character and director relationships, and simplify capacity checks to ensure sufficient storage for productions. Adjust ordering for improved query performance.
This commit is contained in:
@@ -1384,7 +1384,7 @@ WHERE b.falukant_user_id = $1 AND s.stock_type_id = $2;
|
||||
"#;
|
||||
// Produce worker queries
|
||||
pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
SELECT
|
||||
SELECT DISTINCT ON (p.id)
|
||||
p.id AS production_id,
|
||||
p.branch_id,
|
||||
p.product_id,
|
||||
@@ -1411,13 +1411,13 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
ON p.product_id = pr.id
|
||||
JOIN falukant_data.branch br
|
||||
ON p.branch_id = br.id
|
||||
JOIN falukant_data.character c
|
||||
LEFT JOIN falukant_data.character c
|
||||
ON c.user_id = br.falukant_user_id
|
||||
LEFT JOIN falukant_data.knowledge k
|
||||
ON p.product_id = k.product_id
|
||||
AND k.character_id = c.id
|
||||
LEFT JOIN falukant_data.director d
|
||||
ON d.employer_user_id = c.user_id
|
||||
ON d.employer_user_id = br.falukant_user_id
|
||||
LEFT JOIN falukant_data.knowledge k2
|
||||
ON k2.character_id = d.director_character_id
|
||||
AND k2.product_id = p.product_id
|
||||
@@ -1428,7 +1428,7 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
AND pwe.weather_type_id = w.weather_type_id
|
||||
-- Wetter-Effekte derzeit aus der Qualitätsberechnung entfernt
|
||||
WHERE p.start_timestamp + INTERVAL '1 minute' * pr.production_time <= NOW()
|
||||
ORDER BY p.start_timestamp;
|
||||
ORDER BY p.id, p.start_timestamp;
|
||||
"#;
|
||||
|
||||
pub const QUERY_DELETE_PRODUCTION: &str = r#"
|
||||
|
||||
Reference in New Issue
Block a user