Add pagination to WO web UI scan

get_work_orders() only fetched the first 1MB page from DynamoDB.
Loop on LastEvaluatedKey to match the PO web UI pattern.
This commit is contained in:
Adam Moussa 2026-05-12 14:32:41 -04:00
parent 78eb8de067
commit afcd0eabe2

View file

@ -18,9 +18,12 @@ COMMENTS_TABLE = os.environ.get("COMMENTS_TABLE", "WorkOrderComments")
def get_work_orders():
table = dynamodb.Table(WORK_ORDERS_TABLE)
items = []
response = table.scan()
items = response.get("Items", [])
# Sort by updated_at descending
items.extend(response.get("Items", []))
while "LastEvaluatedKey" in response:
response = table.scan(ExclusiveStartKey=response["LastEvaluatedKey"])
items.extend(response.get("Items", []))
items.sort(key=lambda x: x.get("updated_at", ""), reverse=True)
return items