diff options
author | kaniini <nenolod@gmail.com> | 2019-05-07 19:37:41 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2019-05-07 19:37:41 +0000 |
commit | 14deed7f7d0b88d5c8ac19bb3de467429c289746 (patch) | |
tree | e87869cf8a81936954208e5af229b96cfdfc6e58 /test | |
parent | a1a0df19c4521bf0073b6bb8dbf8101cf37ebd6b (diff) | |
parent | d64c3b604e4eb5e8dd3f51aff7d1f15024d5fa33 (diff) | |
download | pleroma-14deed7f7d0b88d5c8ac19bb3de467429c289746.tar.gz pleroma-14deed7f7d0b88d5c8ac19bb3de467429c289746.zip |
Merge branch 'refactor/preload-bookmarks-with-activities' into 'develop'
Optimize bookmarks by preloading them with activities
Closes #861
See merge request pleroma/pleroma!1121
Diffstat (limited to 'test')
-rw-r--r-- | test/activity_test.exs | 45 | ||||
-rw-r--r-- | test/web/mastodon_api/status_view_test.exs | 2 |
2 files changed, 47 insertions, 0 deletions
diff --git a/test/activity_test.exs b/test/activity_test.exs index ad889f544..7e91d534b 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -5,6 +5,7 @@ defmodule Pleroma.ActivityTest do use Pleroma.DataCase alias Pleroma.Activity + alias Pleroma.Bookmark import Pleroma.Factory test "returns an activity by it's AP id" do @@ -28,4 +29,48 @@ defmodule Pleroma.ActivityTest do assert activity == found_activity end + + test "preloading a bookmark" do + user = insert(:user) + user2 = insert(:user) + user3 = insert(:user) + activity = insert(:note_activity) + {:ok, _bookmark} = Bookmark.create(user.id, activity.id) + {:ok, _bookmark2} = Bookmark.create(user2.id, activity.id) + {:ok, bookmark3} = Bookmark.create(user3.id, activity.id) + + queried_activity = + Ecto.Query.from(Pleroma.Activity) + |> Activity.with_preloaded_bookmark(user3) + |> Repo.one() + + assert queried_activity.bookmark == bookmark3 + end + + describe "getting a bookmark" do + test "when association is loaded" do + user = insert(:user) + activity = insert(:note_activity) + {:ok, bookmark} = Bookmark.create(user.id, activity.id) + + queried_activity = + Ecto.Query.from(Pleroma.Activity) + |> Activity.with_preloaded_bookmark(user) + |> Repo.one() + + assert Activity.get_bookmark(queried_activity, user) == bookmark + end + + test "when association is not loaded" do + user = insert(:user) + activity = insert(:note_activity) + {:ok, bookmark} = Bookmark.create(user.id, activity.id) + + queried_activity = + Ecto.Query.from(Pleroma.Activity) + |> Repo.one() + + assert Activity.get_bookmark(queried_activity, user) == bookmark + end + end end diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 5fddc6c58..d7c800e83 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -168,6 +168,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do {:ok, _bookmark} = Bookmark.create(user.id, activity.id) + activity = Activity.get_by_id_with_object(activity.id) + status = StatusView.render("status.json", %{activity: activity, for: user}) assert status.bookmarked == true |