Behebe R-11: Übersicht und Suche lesen in Blöcken und prüfen Rechte vor der Begrenzung.
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 5m53s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 21s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
StommerandClaude Sonnet 5.5 committed 2026-10-22 17:26:06 +02:00
1 parent a3f328832e
commit d0f09830bb
3 files changed
+92 -18

No files matched your search

+43 -17
View File
@@ -1182,37 +1182,61 @@ def post_fulfill(
return deadline_payload(conn, principal.account_id, deadline)
VIEW_LIMIT = 200
SEARCH_LIMIT = 50
SCAN_BATCH = 200
SCAN_CAP = 20000
def _scan(conn, sql: str, params: tuple = ()):
"""Rows in the order of the query, read in batches.
The rights are checked per row after reading. A fixed LIMIT in the query would count rows
of other people too, so the own ones could fall off the end. The reader stops once it has
enough. `SCAN_CAP` bounds the work on very large data sets.
"""
offset = 0
while offset < SCAN_CAP:
rows = conn.execute(f"{sql} LIMIT %s OFFSET %s", (*params, SCAN_BATCH, offset)).fetchall()
yield from rows
if len(rows) < SCAN_BATCH:
return
offset += SCAN_BATCH
@router.get("/api/v1/views/open-tasks")
def open_tasks(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
rows = conn.execute(
items = []
for task in _scan(
conn,
"""
SELECT * FROM tasks
WHERE deleted_at IS NULL AND task_status = 'open'
ORDER BY due_on NULLS LAST, created_at, id
LIMIT 200
"""
).fetchall()
items = []
for task in rows:
""",
):
if _task_visible(conn, principal.account_id, task):
items.append(task_payload(conn, principal.account_id, task))
if len(items) >= VIEW_LIMIT:
break
return {"items": items, "next_cursor": None}
@router.get("/api/v1/views/open-deadlines")
def open_deadlines(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
rows = conn.execute(
items = []
for deadline in _scan(
conn,
"""
SELECT * FROM deadlines
WHERE deleted_at IS NULL AND deadline_status = 'open'
ORDER BY due_on, created_at, id
LIMIT 200
"""
).fetchall()
items = []
for deadline in rows:
""",
):
if _deadline_visible(conn, principal.account_id, deadline):
items.append(deadline_payload(conn, principal.account_id, deadline))
if len(items) >= VIEW_LIMIT:
break
return {"items": items, "next_cursor": None}
@@ -1266,19 +1290,21 @@ def search(q: str, principal: Principal = Depends(get_principal), conn: Connecti
],
}
)
elements = conn.execute(
elements = _scan(
conn,
"""
SELECT e.*
FROM elements e
LEFT JOIN note_bodies n ON n.element_id = e.id
WHERE e.deleted_at IS NULL
AND (e.title ILIKE %s ESCAPE '\\' OR COALESCE(n.document_json::text, '') ILIKE %s ESCAPE '\\')
ORDER BY e.updated_at DESC
LIMIT 100
ORDER BY e.updated_at DESC, e.id
""",
(pattern, pattern),
).fetchall()
)
for element in elements:
if len(items) >= SEARCH_LIMIT:
break
from app.access.policy import visible_bindings_for_element
bindings = visible_bindings_for_element(conn, principal.account_id, element)
@@ -1306,7 +1332,7 @@ def search(q: str, principal: Principal = Depends(get_principal), conn: Connecti
],
}
)
return {"items": items[:50], "next_cursor": None}
return {"items": items[:SEARCH_LIMIT], "next_cursor": None}
@router.patch("/api/v1/cases/{case_id}/content-order")