perf(weather): skip refetch when forecast is fresh

This commit is contained in:
sankalp committed 2026-08-02 13:37:10 +05:45
1 parent 37efa0bf0a
commit 76f275f08d
1 file changed
+16 -10
+16 -10
View File
@@ -387,15 +387,26 @@ class Weather(Service):
def _fetch_weather_data(self) -> None:
try:
GLib.idle_add(self._set_loading, True)
location_data = self._location_cache.get()
from services.config import config
target_loc = config().get("general.weather_location", "").strip()
# Invalidate location cache if the config target changed
location_data = self._location_cache.get(allow_stale=True)
if (
location_data
and location_data.get("config_location", "") == target_loc
and self._weather_cache.is_fresh()
):
# Cached forecast is still fresh and the location target is
# unchanged: skip the network/cache pipeline entirely so
# restarts and in-window refresh() calls avoid redundant
# geolocation/weather fetches and the loading flicker.
return
GLib.idle_add(self._set_loading, True)
location_data = self._location_cache.get()
if location_data and location_data.get("config_location", "") != target_loc:
location_data = None
with self._weather_cache._lock:
@@ -596,8 +607,3 @@ class Weather(Service):
def refresh(self) -> None:
self._start_fetch_thread()
def get_weather_info_for_code(
self, code: int, is_day: int = 1
) -> Tuple[str, str, str, str]:
return get_weather_info(code, is_day)