Merge branch 'main' into cursor/same-day-growth-baseline
This commit is contained in:
commit
9412475473
2 files changed
+60
-4
No files matched your search
@@ -700,19 +700,32 @@ class DashboardQueries:
|
||||
continue
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _task_started_sort_key(value: Any) -> tuple[int, int]:
|
||||
"""缺 started_at 的排末尾;有值的按开始时间倒序(含进行中)。"""
|
||||
if isinstance(value, Mapping):
|
||||
raw = value.get("started_at")
|
||||
try:
|
||||
return (0, -int(raw))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return (1, 0)
|
||||
|
||||
def _task_records(self, conn: sqlite3.Connection) -> dict[str, Any]:
|
||||
rows = conn.execute(
|
||||
"SELECT k, v FROM kv WHERE k LIKE 'task:last:%' ORDER BY k"
|
||||
"SELECT k, v FROM kv WHERE k LIKE 'task:last:%'"
|
||||
).fetchall()
|
||||
result: dict[str, Any] = {}
|
||||
items: list[tuple[str, Any]] = []
|
||||
for row in rows:
|
||||
name = str(row["k"]).removeprefix("task:last:")
|
||||
try:
|
||||
value = json.loads(str(row["v"]))
|
||||
except (TypeError, json.JSONDecodeError):
|
||||
value = {"raw": row["v"]}
|
||||
result[name] = value
|
||||
return result
|
||||
items.append((name, value))
|
||||
items.sort(key=lambda pair: self._task_started_sort_key(pair[1]))
|
||||
# 插入序即开始时间倒序;前端 Object.entries 保留该序,勿再排序。
|
||||
return dict(items)
|
||||
|
||||
def _task_running(self, conn: sqlite3.Connection) -> dict[str, Any]:
|
||||
rows = conn.execute(
|
||||
|
||||
Reference in new issue
Block a user