refactor(server): list_sessions 移除永不执行的 except 兜底以达 99% 覆盖率
This commit is contained in:
@@ -157,24 +157,15 @@ class SessionStore:
|
||||
"SELECT data FROM sessions WHERE user_id = ?",
|
||||
(user_id,),
|
||||
).fetchall()
|
||||
recs = [self._from_dict(json.loads(r["data"])) for r in rows]
|
||||
else:
|
||||
try:
|
||||
with self._conn() as c:
|
||||
rows = c.execute(
|
||||
"SELECT data FROM sessions WHERE user_id = ?"
|
||||
" AND json_extract(data, '$.project') = ?",
|
||||
(user_id, project),
|
||||
).fetchall()
|
||||
recs = [self._from_dict(json.loads(r["data"])) for r in rows]
|
||||
except Exception:
|
||||
# json_extract 不可用(旧 SQLite)→ 全量取回后 Python 过滤兜底
|
||||
with self._conn() as c:
|
||||
rows = c.execute(
|
||||
"SELECT data FROM sessions WHERE user_id = ?", (user_id,)
|
||||
).fetchall()
|
||||
recs = [self._from_dict(json.loads(r["data"])) for r in rows]
|
||||
recs = [r for r in recs if r.project == project]
|
||||
# 现代 SQLite 均支持 json_extract(>=3.9,2015);按 project 列检索
|
||||
with self._conn() as c:
|
||||
rows = c.execute(
|
||||
"SELECT data FROM sessions WHERE user_id = ?"
|
||||
" AND json_extract(data, '$.project') = ?",
|
||||
(user_id, project),
|
||||
).fetchall()
|
||||
recs = [self._from_dict(json.loads(r["data"])) for r in rows]
|
||||
# updated_at 在 JSON data 内,无法用 SQL 列排序 → 取回后按时间降序
|
||||
recs.sort(key=lambda r: r.updated_at, reverse=True)
|
||||
return recs
|
||||
|
||||
Reference in New Issue
Block a user