fix: 重新登录后清掉上一轮已结束的运行状态

- 服务重启留下的「已中断」状态会在登录后继续压着卡片徽标、挂着旧进度和红条
- 登录成功后清掉该账号已结束的运行状态(内存 + run_state 表),正在跑的不动,内存日志保留
- 新增 store.run_state_delete(),/api/run 轮询随即把 run 置空,徽标回到「已登录」
This commit is contained in:
study-tool
2026-10-31 01:00:57 +08:00
parent e6515fe278
commit 0e2923e675
4 changed files with 33 additions and 1 deletions
+27
View File
@@ -23,6 +23,32 @@ def _log_login(username, ok, code, error, elapsed, stage=""):
pass
_RUN_FIELDS = ("status", "error", "progress", "done", "total", "course",
"started", "finished_at")
def _clear_done_run(account_id):
"""重新登录后清掉上一轮已经结束的运行状态。
服务重启会把上次没跑完的运行标成「已中断」,那条状态会一直压着卡片的
「已登录」徽标、还挂着旧进度和红条;登录成功说明用户开始新一轮,
这时就该把它清掉。正在跑的(discovering / studying)绝不能动,
否则会把实时进度清没。内存里保留 log,卡片日志不受影响。
"""
key = str(account_id or "")
if not key:
return
with RUNS_LOCK:
st = RUNS.get(key)
if st and st.get("status") in ("discovering", "studying"):
return
if st:
for field in _RUN_FIELDS:
st.pop(field, None)
st["updated"] = time.time()
store.run_state_delete(key)
def _login_account(b: LoginIn):
"""解析出一组可登录的凭据:显式传入优先,否则按账号 id 从库里取。"""
acc = store.account_get(b.account_id) if b.account_id else None
@@ -65,6 +91,7 @@ def api_login(b: LoginIn):
_log_login(username, True, "ok", warn, time.time() - t0, "user=%s" % user)
if acc:
store.account_save_login(acc["id"], user, cookies, courses)
_clear_done_run(acc["id"]) # 上一轮已结束的运行状态不再挂在新会话上
return {"ok": True, "user": user, "cookies": cookies, "courses": courses, "warn": warn}
+4
View File
@@ -487,6 +487,10 @@ def run_state_all():
return out
def run_state_delete(key):
write("DELETE FROM run_state WHERE key=?", (str(key or ""),))
# ------------------------------------------------------------------ 页面快照
def snapshot_add(plan_id, project_id, url, html):