Refactor notification handling in Workers: Centralize notification insertion and frontend updates by replacing direct SQL queries with dedicated functions. This improves code maintainability and reduces redundancy across character creation, events, and transport processing.

This commit is contained in:
Torsten Schulz (local)
2025-12-22 13:58:17 +01:00
parent a82d554494
commit fce7400303
7 changed files with 183 additions and 47 deletions

View File

@@ -13,7 +13,6 @@ use crate::worker::sql::{
QUERY_GET_RANDOM_INFANT,
QUERY_GET_RANDOM_CITY,
QUERY_GET_AFFECTED_USERS,
QUERY_INSERT_NOTIFICATION,
QUERY_GET_MONEY,
QUERY_UPDATE_MONEY,
QUERY_GET_REGION_STOCKS,
@@ -53,6 +52,7 @@ use crate::worker::sql::{
QUERY_GET_CREDIT_DEBT,
QUERY_COUNT_CHILDREN,
};
use crate::worker::{insert_notification, publish_update_status};
/// Typisierung von Ereignissen
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -1617,17 +1617,11 @@ impl EventsWorker {
user_id: i32,
event_type: &str,
) -> Result<(), DbError> {
let mut conn = pool
.get()
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
// DB-Notification (zentralisiert). Historisch wird hier als `tr` der event_type-String gespeichert.
insert_notification(pool, user_id, event_type, None)?;
conn.prepare("insert_notification", QUERY_INSERT_NOTIFICATION)?;
conn.execute("insert_notification", &[&user_id, &event_type])?;
// falukantUpdateStatus
let update_message =
format!(r#"{{"event":"falukantUpdateStatus","user_id":{}}}"#, user_id);
broker.publish(update_message);
// Frontend-Update (zentralisiert)
publish_update_status(broker, user_id);
// ursprüngliche Benachrichtigung
let message =