Conversations: Fetch users in one query.
authorlain <lain@soykaf.club>
Fri, 7 Jun 2019 15:51:47 +0000 (17:51 +0200)
committerlain <lain@soykaf.club>
Fri, 7 Jun 2019 15:51:47 +0000 (17:51 +0200)
lib/pleroma/conversation/participation.ex
test/conversation/participation_test.exs

index 2c13c4b408a3ac9a434be385b1cd77ee23dea016..5883e4183780ef3e1f32b4d44cb4da60ed0ca4f8 100644 (file)
@@ -59,10 +59,10 @@ defmodule Pleroma.Conversation.Participation do
   def for_user(user, params \\ %{}) do
     from(p in __MODULE__,
       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)
-    |> Repo.preload(conversation: [:users])
   end
 
   def for_user_with_last_activity_id(user, params \\ %{}) do
index 0e60bfca539e51e162129acff922b08761835f77..2a03e5d67a722f4459fbef1174f6ef8b25a9f920 100644 (file)
@@ -72,8 +72,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
     object2 = Pleroma.Object.normalize(activity_two)
     object3 = Pleroma.Object.normalize(activity_three)
 
+    user = Repo.get(Pleroma.User, user.id)
+
     assert participation_one.conversation.ap_id == object3.data["context"]
     assert participation_two.conversation.ap_id == object2.data["context"]
+    assert participation_one.conversation.users == [user]
 
     # Pagination
     assert [participation_one] = Participation.for_user(user, %{"limit" => 1})