Refactor SQL queries into a dedicated module
- Moved SQL queries from multiple worker files into `src/worker/sql.rs` for better organization and maintainability. - Updated references in `stockage_manager.rs`, `transport.rs`, `underground.rs`, `user_character.rs`, and `value_recalculation.rs` to use the new centralized SQL queries. - Improved code readability by replacing `.get(0)` with `.first()` for better clarity when retrieving the first row from query results. - Cleaned up unnecessary comments and consolidated related SQL queries.
This commit is contained in:
@@ -5,48 +5,17 @@ use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use super::base::{BaseWorker, Worker, WorkerState};
|
||||
use crate::worker::sql::{
|
||||
QUERY_GET_NEW_HOUSE_DATA,
|
||||
QUERY_ADD_NEW_BUYABLE_HOUSE,
|
||||
QUERY_UPDATE_BUYABLE_HOUSE_STATE,
|
||||
QUERY_UPDATE_USER_HOUSE_STATE,
|
||||
};
|
||||
|
||||
pub struct HouseWorker {
|
||||
base: BaseWorker,
|
||||
}
|
||||
|
||||
// SQL-Queries analog zu `houseworker.h`
|
||||
const QUERY_GET_NEW_HOUSE_DATA: &str = r#"
|
||||
SELECT
|
||||
h.id AS house_id
|
||||
FROM
|
||||
falukant_type.house AS h
|
||||
WHERE
|
||||
random() < 0.0001
|
||||
AND label_tr <> 'under_bridge';
|
||||
"#;
|
||||
|
||||
const QUERY_ADD_NEW_BUYABLE_HOUSE: &str = r#"
|
||||
INSERT INTO falukant_data.buyable_house (house_type_id)
|
||||
VALUES ($1);
|
||||
"#;
|
||||
|
||||
const QUERY_UPDATE_BUYABLE_HOUSE_STATE: &str = r#"
|
||||
UPDATE falukant_data.buyable_house
|
||||
SET roof_condition = ROUND(roof_condition - random() * (3 + 0 * id)),
|
||||
floor_condition = ROUND(floor_condition - random() * (3 + 0 * id)),
|
||||
wall_condition = ROUND(wall_condition - random() * (3 + 0 * id)),
|
||||
window_condition = ROUND(window_condition - random() * (3 + 0 * id));
|
||||
"#;
|
||||
|
||||
const QUERY_UPDATE_USER_HOUSE_STATE: &str = r#"
|
||||
UPDATE falukant_data.user_house
|
||||
SET roof_condition = ROUND(roof_condition - random() * (3 + 0 * id)),
|
||||
floor_condition = ROUND(floor_condition - random() * (3 + 0 * id)),
|
||||
wall_condition = ROUND(wall_condition - random() * (3 + 0 * id)),
|
||||
window_condition = ROUND(window_condition - random() * (3 + 0 * id))
|
||||
WHERE house_type_id NOT IN (
|
||||
SELECT id
|
||||
FROM falukant_type.house h
|
||||
WHERE h.label_tr = 'under_bridge'
|
||||
);
|
||||
"#;
|
||||
|
||||
impl HouseWorker {
|
||||
pub fn new(pool: ConnectionPool, broker: MessageBroker) -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user