Fun changes
This commit is contained in:
parent
cd778dd088
commit
349a6c1d53
60 changed files with 1260 additions and 2600 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue