mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-24 01:33:46 +08:00
Revert "Comments... because Ill never remember this"
This reverts commit 07adabd70d.
This commit is contained in:
@@ -17,14 +17,9 @@ import time
|
|||||||
|
|
||||||
|
|
||||||
class SettingsParamsWrapper:
|
class SettingsParamsWrapper:
|
||||||
"""
|
|
||||||
Proxy for ui_state.params. Relies on CachedParams for global TTL caching.
|
|
||||||
Intercepts UI writes (put/remove) to trigger system migrations automatically.
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._params = ui_state.params
|
self._params = ui_state.params
|
||||||
|
|
||||||
# --- Read Operations (Forwarded directly to global TTL cache) ---
|
|
||||||
def get(self, key, **kwargs):
|
def get(self, key, **kwargs):
|
||||||
return self._params.get(key, **kwargs)
|
return self._params.get(key, **kwargs)
|
||||||
|
|
||||||
@@ -38,10 +33,8 @@ class SettingsParamsWrapper:
|
|||||||
return self._params.get_float(key, **kwargs)
|
return self._params.get_float(key, **kwargs)
|
||||||
|
|
||||||
def _notify_changed(self):
|
def _notify_changed(self):
|
||||||
# Triggers backend state sync when UI settings are modified
|
|
||||||
update_starpilot_toggles()
|
update_starpilot_toggles()
|
||||||
|
|
||||||
# --- Write Operations (Triggers side-effects) ---
|
|
||||||
def put(self, key, val, **kwargs):
|
def put(self, key, val, **kwargs):
|
||||||
self._params.put(key, val, **kwargs)
|
self._params.put(key, val, **kwargs)
|
||||||
self._notify_changed()
|
self._notify_changed()
|
||||||
@@ -62,7 +55,6 @@ class SettingsParamsWrapper:
|
|||||||
self._params.remove(key)
|
self._params.remove(key)
|
||||||
self._notify_changed()
|
self._notify_changed()
|
||||||
|
|
||||||
# Safety net for any newly added parameter methods
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self._params, name)
|
return getattr(self._params, name)
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ from openpilot.system.hardware import HARDWARE, PC
|
|||||||
BACKLIGHT_OFFROAD = 65 if HARDWARE.get_device_type() == "mici" else 50
|
BACKLIGHT_OFFROAD = 65 if HARDWARE.get_device_type() == "mici" else 50
|
||||||
USBGPU_POLL_INTERVAL = 1.0
|
USBGPU_POLL_INTERVAL = 1.0
|
||||||
class CachedParams:
|
class CachedParams:
|
||||||
"""
|
|
||||||
Global TTL-based cache for Params() to prevent excessive disk/IPC reads.
|
|
||||||
Dynamically wraps read methods (get*) to cache values and write methods (put*) to invalidate stale cache.
|
|
||||||
"""
|
|
||||||
def __init__(self, ttl: float = 1.0):
|
def __init__(self, ttl: float = 1.0):
|
||||||
self._params = Params()
|
self._params = Params()
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
@@ -28,7 +24,6 @@ class CachedParams:
|
|||||||
self._ttl = ttl
|
self._ttl = ttl
|
||||||
|
|
||||||
def _invalidate(self, key=None):
|
def _invalidate(self, key=None):
|
||||||
# Clears specific key or entire cache to guarantee fresh reads after writes
|
|
||||||
if key is None:
|
if key is None:
|
||||||
self._cache.clear()
|
self._cache.clear()
|
||||||
else:
|
else:
|
||||||
@@ -44,7 +39,6 @@ class CachedParams:
|
|||||||
return attr
|
return attr
|
||||||
|
|
||||||
if name.startswith("get"):
|
if name.startswith("get"):
|
||||||
# Intercept reads to serve from RAM if TTL is valid
|
|
||||||
def get_wrapper(key, *args, **kwargs):
|
def get_wrapper(key, *args, **kwargs):
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
k_str = key.decode("utf-8") if isinstance(key, bytes) else str(key)
|
k_str = key.decode("utf-8") if isinstance(key, bytes) else str(key)
|
||||||
@@ -59,7 +53,6 @@ class CachedParams:
|
|||||||
return get_wrapper
|
return get_wrapper
|
||||||
|
|
||||||
if name.startswith("put") or name.startswith("remove") or name.startswith("clear"):
|
if name.startswith("put") or name.startswith("remove") or name.startswith("clear"):
|
||||||
# Intercept writes to immediately invalidate stale data
|
|
||||||
def put_wrapper(key=None, *args, **kwargs):
|
def put_wrapper(key=None, *args, **kwargs):
|
||||||
res = attr(key, *args, **kwargs) if key is not None else attr(*args, **kwargs)
|
res = attr(key, *args, **kwargs) if key is not None else attr(*args, **kwargs)
|
||||||
self._invalidate(key)
|
self._invalidate(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user