Fun changes
Some checks failed
CI / Python (lint + test) (push) Failing after 3m38s
CI / Rust (lint + test) (push) Failing after 3m32s
CI / Frontend (lint + typecheck) (push) Failing after 4m12s
Build and publish Docker image / build-and-push (push) Failing after 4m48s

This commit is contained in:
Andras Schmelczer 2026-04-04 22:59:44 +01:00
parent cd778dd088
commit 349a6c1d53
60 changed files with 1260 additions and 2600 deletions

View file

@ -1,5 +1,3 @@
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use parking_lot::RwLock;
@ -14,7 +12,6 @@ use crate::routes::FeaturesResponse;
use crate::utils::GridIndex;
pub struct AppState {
// --- Rebuilt on reload ---
pub data: PropertyData,
pub grid: GridIndex,
/// h3_cells[row_idx] = precomputed H3 cell ID at max resolution (12).
@ -33,7 +30,6 @@ pub struct AppState {
/// Complete system prompt for AI filters (features + examples + instructions)
pub ai_filters_system_prompt: String,
// --- Shared across reloads (Arc for cheap cloning) ---
pub poi_data: Arc<POIData>,
pub poi_grid: Arc<GridIndex>,
pub place_data: Arc<PlaceData>,
@ -81,34 +77,16 @@ pub struct AppState {
pub stripe_referral_coupon_id: String,
}
/// Wraps AppState with atomic swap capability for hot-reloading.
/// Wraps AppState for shared access across route handlers.
/// Route handlers call `load_state()` to get the current snapshot.
/// The reload endpoint builds a new AppState and swaps it in atomically.
pub struct SharedState {
current: RwLock<Arc<AppState>>,
reloading: AtomicBool,
/// Paths needed for data reload
pub properties_path: PathBuf,
pub postcode_features_path: PathBuf,
pub listings_buy_path: PathBuf,
pub listings_rent_path: PathBuf,
}
impl SharedState {
pub fn new(
state: AppState,
properties_path: PathBuf,
postcode_features_path: PathBuf,
listings_buy_path: PathBuf,
listings_rent_path: PathBuf,
) -> Self {
pub fn new(state: AppState) -> Self {
Self {
current: RwLock::new(Arc::new(state)),
reloading: AtomicBool::new(false),
properties_path,
postcode_features_path,
listings_buy_path,
listings_rent_path,
}
}
@ -116,21 +94,4 @@ impl SharedState {
pub fn load_state(&self) -> Arc<AppState> {
self.current.read().clone()
}
/// Atomically swap in a new AppState. Old state is dropped when all references are gone.
pub fn swap_state(&self, new_state: AppState) {
*self.current.write() = Arc::new(new_state);
}
/// Try to mark reload as in-progress. Returns false if already reloading.
pub fn try_start_reload(&self) -> bool {
self.reloading
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
.is_ok()
}
/// Mark reload as complete.
pub fn finish_reload(&self) {
self.reloading.store(false, Ordering::Release);
}
}