-
Notifications
You must be signed in to change notification settings - Fork 634
Open
Description
Optional, but maybe worth it, since you already touched the SketchListResource class in this PR:
- The
recentscope bypasses the pagination logic passed via the form. We could use the chance to add in support for that as well instead of hardcoding it to last 10? - The
recentscope currently fetches the last 10 View objects and then, for each view, it fetches the associated Sketch and its Status. This requires basically N+1 database queries which can slow down the API endpoint. We can fetch all the "last activity" timestamps in a single, efficient query instead after you have the list of sketches from the paginator, and then use a dictionary lookup in the loop.
This could look something like this (untested):
from sqlalchemy.orm import joinedload, subqueryload
from timesketch.models.sketch import Sketch, View
[...]
if scope == "recent":
views = (
View.query.options(
joinedload(View.sketch).subqueryload(Sketch.status)
)
.filter_by(user=current_user, name="")
.order_by(View.updated_at.desc())
.limit(10) # Or use pagination logic here
)
sketches = [
view.sketch
for view in views
if view.sketch.get_status.status != "deleted"
]
total_items = len(sketches)
[...]
Originally posted by @jkppr in #3470 (comment)
Metadata
Metadata
Assignees
Labels
No labels