Improve performance of filtering notes in NotesController

Reduces the number of queries needed to redact notes to which
the user does not have access. Also includes an N+1 query test
as a guard against future issues.

This is a follow-up from
86 jobs for sh-improve-perf-notes-actions in 72 minutes and 41 seconds (queued for 7 seconds)