forked from AkkomaGang/akkoma
activitypub: allow skipping preload in some cases (like certain tests where the preload is obnoxious)
This commit is contained in:
parent
ba7299fc87
commit
73efe95368
2 changed files with 29 additions and 10 deletions
|
@ -718,6 +718,13 @@ defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
|
||||||
|
|
||||||
defp restrict_muted_reblogs(query, _), do: query
|
defp restrict_muted_reblogs(query, _), do: query
|
||||||
|
|
||||||
|
defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
|
||||||
|
|
||||||
|
defp maybe_preload_objects(query, _) do
|
||||||
|
query
|
||||||
|
|> Activity.with_preloaded_object()
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_activities_query(recipients, opts \\ %{}) do
|
def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
base_query =
|
base_query =
|
||||||
from(
|
from(
|
||||||
|
@ -725,9 +732,9 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
limit: 20,
|
limit: 20,
|
||||||
order_by: [fragment("? desc nulls last", activity.id)]
|
order_by: [fragment("? desc nulls last", activity.id)]
|
||||||
)
|
)
|
||||||
|> Activity.with_preloaded_object()
|
|
||||||
|
|
||||||
base_query
|
base_query
|
||||||
|
|> maybe_preload_objects(opts)
|
||||||
|> restrict_recipients(recipients, opts["user"])
|
|> restrict_recipients(recipients, opts["user"])
|
||||||
|> restrict_tag(opts)
|
|> restrict_tag(opts)
|
||||||
|> restrict_tag_reject(opts)
|
|> restrict_tag_reject(opts)
|
||||||
|
|
|
@ -270,7 +270,8 @@ test "doesn't return blocked activities" do
|
||||||
booster = insert(:user)
|
booster = insert(:user)
|
||||||
{:ok, user} = User.block(user, %{ap_id: activity_one.data["actor"]})
|
{:ok, user} = User.block(user, %{ap_id: activity_one.data["actor"]})
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
|
@ -278,7 +279,8 @@ test "doesn't return blocked activities" do
|
||||||
|
|
||||||
{:ok, user} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
|
{:ok, user} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
|
@ -289,14 +291,16 @@ test "doesn't return blocked activities" do
|
||||||
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
||||||
activity_three = Repo.get(Activity, activity_three.id)
|
activity_three = Repo.get(Activity, activity_three.id)
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
refute Enum.member?(activities, activity_three)
|
refute Enum.member?(activities, activity_three)
|
||||||
refute Enum.member?(activities, boost_activity)
|
refute Enum.member?(activities, boost_activity)
|
||||||
assert Enum.member?(activities, activity_one)
|
assert Enum.member?(activities, activity_one)
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"blocking_user" => nil})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{"blocking_user" => nil, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
|
@ -312,14 +316,20 @@ test "doesn't return muted activities" do
|
||||||
booster = insert(:user)
|
booster = insert(:user)
|
||||||
{:ok, user} = User.mute(user, %User{ap_id: activity_one.data["actor"]})
|
{:ok, user} = User.mute(user, %User{ap_id: activity_one.data["actor"]})
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
refute Enum.member?(activities, activity_one)
|
refute Enum.member?(activities, activity_one)
|
||||||
|
|
||||||
# Calling with 'with_muted' will deliver muted activities, too.
|
# Calling with 'with_muted' will deliver muted activities, too.
|
||||||
activities = ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{
|
||||||
|
"muting_user" => user,
|
||||||
|
"with_muted" => true,
|
||||||
|
"skip_preload" => true
|
||||||
|
})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
|
@ -327,7 +337,8 @@ test "doesn't return muted activities" do
|
||||||
|
|
||||||
{:ok, user} = User.unmute(user, %User{ap_id: activity_one.data["actor"]})
|
{:ok, user} = User.unmute(user, %User{ap_id: activity_one.data["actor"]})
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
|
@ -338,14 +349,15 @@ test "doesn't return muted activities" do
|
||||||
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
|
||||||
activity_three = Repo.get(Activity, activity_three.id)
|
activity_three = Repo.get(Activity, activity_three.id)
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
refute Enum.member?(activities, activity_three)
|
refute Enum.member?(activities, activity_three)
|
||||||
refute Enum.member?(activities, boost_activity)
|
refute Enum.member?(activities, boost_activity)
|
||||||
assert Enum.member?(activities, activity_one)
|
assert Enum.member?(activities, activity_one)
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([], %{"muting_user" => nil})
|
activities = ActivityPub.fetch_activities([], %{"muting_user" => nil, "skip_preload" => true})
|
||||||
|
|
||||||
assert Enum.member?(activities, activity_two)
|
assert Enum.member?(activities, activity_two)
|
||||||
assert Enum.member?(activities, activity_three)
|
assert Enum.member?(activities, activity_three)
|
||||||
|
|
Loading…
Reference in a new issue