Merge branch 'preload-changes' into 'develop'

Conversations: Fetch users in one query.

See merge request pleroma/pleroma!1258
This commit is contained in:
kaniini 2019-06-11 02:37:08 +00:00
commit f2d72b1fe4
2 changed files with 5 additions and 2 deletions

View file

@ -59,10 +59,10 @@ defmodule Pleroma.Conversation.Participation do
def for_user(user, params \\ %{}) do def for_user(user, params \\ %{}) do
from(p in __MODULE__, from(p in __MODULE__,
where: p.user_id == ^user.id, where: p.user_id == ^user.id,
order_by: [desc: p.updated_at] order_by: [desc: p.updated_at],
preload: [conversation: [:users]]
) )
|> Pleroma.Pagination.fetch_paginated(params) |> Pleroma.Pagination.fetch_paginated(params)
|> Repo.preload(conversation: [:users])
end end
def for_user_with_last_activity_id(user, params \\ %{}) do def for_user_with_last_activity_id(user, params \\ %{}) do

View file

@ -72,8 +72,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
object2 = Pleroma.Object.normalize(activity_two) object2 = Pleroma.Object.normalize(activity_two)
object3 = Pleroma.Object.normalize(activity_three) object3 = Pleroma.Object.normalize(activity_three)
user = Repo.get(Pleroma.User, user.id)
assert participation_one.conversation.ap_id == object3.data["context"] assert participation_one.conversation.ap_id == object3.data["context"]
assert participation_two.conversation.ap_id == object2.data["context"] assert participation_two.conversation.ap_id == object2.data["context"]
assert participation_one.conversation.users == [user]
# Pagination # Pagination
assert [participation_one] = Participation.for_user(user, %{"limit" => 1}) assert [participation_one] = Participation.for_user(user, %{"limit" => 1})