mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-08 11:56:59 +00:00
Speed up task activity load
This commit is contained in:
+13
-2
@@ -894,10 +894,11 @@ def setup_task_routes(task_scheduler) -> APIRouter:
|
|||||||
return {"ok": True, "message": "Task stopped"}
|
return {"ok": True, "message": "Task stopped"}
|
||||||
|
|
||||||
@router.get("/runs/recent")
|
@router.get("/runs/recent")
|
||||||
async def list_recent_runs(request: Request, limit: int = 50):
|
async def list_recent_runs(request: Request, limit: int = 50, max_result_chars: int = 6000):
|
||||||
"""Recent task runs across ALL tasks for this owner. Drives the Activity view."""
|
"""Recent task runs across ALL tasks for this owner. Drives the Activity view."""
|
||||||
user = _owner(request)
|
user = _owner(request)
|
||||||
limit = max(1, min(limit, 200))
|
limit = max(1, min(limit, 200))
|
||||||
|
max_result_chars = max(500, min(max_result_chars, 20000))
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
try:
|
try:
|
||||||
q = db.query(TaskRun, ScheduledTask).join(
|
q = db.query(TaskRun, ScheduledTask).join(
|
||||||
@@ -931,10 +932,20 @@ def setup_task_routes(task_scheduler) -> APIRouter:
|
|||||||
deduped.append((r, t))
|
deduped.append((r, t))
|
||||||
if len(deduped) >= limit:
|
if len(deduped) >= limit:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def _clip_run(r: TaskRun) -> dict:
|
||||||
|
d = _run_to_dict(r)
|
||||||
|
for key in ("result", "error"):
|
||||||
|
val = d.get(key)
|
||||||
|
if isinstance(val, str) and len(val) > max_result_chars:
|
||||||
|
d[key] = val[:max_result_chars].rstrip() + "\n\n[Activity preview truncated]"
|
||||||
|
return d
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
"has_more": len(rows) > len(deduped),
|
||||||
"runs": [
|
"runs": [
|
||||||
{
|
{
|
||||||
**_run_to_dict(r),
|
**_clip_run(r),
|
||||||
"task_name": _display_task_name(t),
|
"task_name": _display_task_name(t),
|
||||||
"task_type": t.task_type or "llm",
|
"task_type": t.task_type or "llm",
|
||||||
"action": t.action,
|
"action": t.action,
|
||||||
|
|||||||
+15
-1
@@ -2001,6 +2001,17 @@ async function _renderActivityView() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list.innerHTML = _stackActivityEntries(filtered).map(_renderActivityEntry).join('');
|
list.innerHTML = _stackActivityEntries(filtered).map(_renderActivityEntry).join('');
|
||||||
|
if (_activityHasMore && !q) {
|
||||||
|
list.insertAdjacentHTML('beforeend', `
|
||||||
|
<button type="button" class="memory-toolbar-btn tasks-activity-load-more" id="tasks-activity-load-more" style="width:100%;justify-content:center;margin-top:6px;">
|
||||||
|
Load more
|
||||||
|
</button>
|
||||||
|
`);
|
||||||
|
list.querySelector('#tasks-activity-load-more')?.addEventListener('click', () => {
|
||||||
|
_activityLimit = Math.min(200, _activityLimit + 40);
|
||||||
|
_renderActivityView();
|
||||||
|
});
|
||||||
|
}
|
||||||
_wireActivityRows(list);
|
_wireActivityRows(list);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2060,10 +2071,11 @@ async function _renderActivityView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/api/tasks/runs/recent?limit=100`, { credentials: 'same-origin' });
|
const res = await fetch(`${API_BASE}/api/tasks/runs/recent?limit=${_activityLimit}&max_result_chars=6000`, { credentials: 'same-origin' });
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const runs = data.runs || [];
|
const runs = data.runs || [];
|
||||||
|
_activityHasMore = !!data.has_more && _activityLimit < 200;
|
||||||
const list = document.getElementById('tasks-activity-list');
|
const list = document.getElementById('tasks-activity-list');
|
||||||
if (!list) return;
|
if (!list) return;
|
||||||
if (runs.length === 0) {
|
if (runs.length === 0) {
|
||||||
@@ -2105,6 +2117,8 @@ async function _renderActivityView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let _activityEntries = [];
|
let _activityEntries = [];
|
||||||
|
let _activityLimit = 40;
|
||||||
|
let _activityHasMore = false;
|
||||||
|
|
||||||
function _stackActivityEntries(entries) {
|
function _stackActivityEntries(entries) {
|
||||||
const out = [];
|
const out = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user