perf: optimize get_notes_by_user_id to reduce database queries
- Replace inefficient memory-based filtering with database-level filtering - Add proper access control conditions to SQL query - Reduce memory usage by filtering at database level instead of loading all notes - Maintain access control validation with post-filtering for complex cases This change significantly improves performance for users with many notes by reducing the number of database queries and memory usage. Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
This commit is contained in:
@@ -48,7 +48,7 @@ async def get_notes(request: Request, user=Depends(get_verified_user)):
|
||||
"user": UserResponse(**Users.get_user_by_id(note.user_id).model_dump()),
|
||||
}
|
||||
)
|
||||
for note in Notes.get_notes_by_user_id(user.id, "write")
|
||||
for note in Notes.get_notes_by_access(user.id, "write")
|
||||
]
|
||||
|
||||
return notes
|
||||
@@ -81,7 +81,7 @@ async def get_note_list(
|
||||
|
||||
notes = [
|
||||
NoteTitleIdResponse(**note.model_dump())
|
||||
for note in Notes.get_notes_by_user_id(user.id, "write", skip=skip, limit=limit)
|
||||
for note in Notes.get_notes_by_access(user.id, "write", skip=skip, limit=limit)
|
||||
]
|
||||
|
||||
return notes
|
||||
|
||||
Reference in New Issue
Block a user