light poller commit1
This commit is contained in:
@@ -4,6 +4,8 @@ from threading import RLock
|
||||
from time import time
|
||||
from . import rtorrent, operation_logs
|
||||
|
||||
_LIVE_KEYS = {"state", "active", "paused", "complete", "completed_bytes", "progress", "ratio", "up_rate", "up_rate_h", "down_rate", "down_rate_h", "eta_seconds", "eta_h", "up_total", "up_total_h", "down_total", "down_total_h", "to_download", "to_download_h", "peers", "seeds", "message", "status", "post_check", "hashing"}
|
||||
|
||||
_VOLATILE = {"down_rate", "down_rate_h", "up_rate", "up_rate_h", "progress", "completed_bytes", "peers", "seeds", "ratio", "state", "status", "message", "down_total", "down_total_h", "to_download", "to_download_h", "up_total", "up_total_h"}
|
||||
|
||||
|
||||
@@ -33,6 +35,42 @@ class TorrentCache:
|
||||
self._updated_at.pop(profile_id, None)
|
||||
return removed
|
||||
|
||||
|
||||
def refresh_live(self, profile: dict) -> dict:
|
||||
"""Refresh only volatile live fields without replacing the full cached torrent rows."""
|
||||
# Note: The fast poller uses this lightweight path so speeds/statuses can update often while the full list poller stays slower.
|
||||
profile_id = int(profile["id"])
|
||||
try:
|
||||
rows = rtorrent.list_torrent_live_stats(profile)
|
||||
live = {t["hash"]: t for t in rows if t.get("hash")}
|
||||
with self._lock:
|
||||
old = dict(self._data.get(profile_id, {}))
|
||||
if not old:
|
||||
self._errors[profile_id] = ""
|
||||
return {"ok": True, "profile_id": profile_id, "updated": [], "missing": [], "unknown": list(live.keys()), "requires_full_refresh": bool(live)}
|
||||
updated = []
|
||||
for h, live_row in live.items():
|
||||
current = old.get(h)
|
||||
if not current:
|
||||
continue
|
||||
patch = {"hash": h}
|
||||
for key in _LIVE_KEYS:
|
||||
if key in live_row and current.get(key) != live_row.get(key):
|
||||
patch[key] = live_row.get(key)
|
||||
if len(patch) > 1:
|
||||
current.update({k: v for k, v in patch.items() if k != "hash"})
|
||||
updated.append(patch)
|
||||
missing = [h for h in old.keys() if h not in live]
|
||||
unknown = [h for h in live.keys() if h not in old]
|
||||
self._data[profile_id] = old
|
||||
self._errors[profile_id] = ""
|
||||
self._updated_at[profile_id] = time()
|
||||
return {"ok": True, "profile_id": profile_id, "updated": updated, "missing": missing, "unknown": unknown, "requires_full_refresh": bool(missing or unknown)}
|
||||
except Exception as exc:
|
||||
with self._lock:
|
||||
self._errors[profile_id] = str(exc)
|
||||
return {"ok": False, "profile_id": profile_id, "error": str(exc), "updated": [], "missing": [], "unknown": [], "requires_full_refresh": False}
|
||||
|
||||
def refresh(self, profile: dict) -> dict:
|
||||
profile_id = int(profile["id"])
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user