Join on preloads to avoid N+1 queries
This commit is contained in:
parent
6383fa3a5d
commit
8018ae7ae5
2 changed files with 10 additions and 3 deletions
|
|
@ -35,7 +35,8 @@ defmodule Pleroma.Notification do
|
|||
n in Notification,
|
||||
where: n.user_id == ^user.id,
|
||||
order_by: [desc: n.id],
|
||||
preload: [:activity],
|
||||
join: activity in assoc(n, :activity),
|
||||
preload: [activity: activity],
|
||||
limit: 20
|
||||
)
|
||||
|
||||
|
|
@ -66,7 +67,8 @@ defmodule Pleroma.Notification do
|
|||
from(
|
||||
n in Notification,
|
||||
where: n.id == ^id,
|
||||
preload: [:activity]
|
||||
join: activity in assoc(n, :activity),
|
||||
preload: [activity: activity]
|
||||
)
|
||||
|
||||
notification = Repo.one(query)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue