Do not attempt to schedule poll refresh jobs for local activities

This commit is contained in:
Mark Felder 2024-10-02 11:05:17 -04:00
parent 9ff57946e7
commit 0a42a3f2ea
2 changed files with 23 additions and 2 deletions

View file

@ -34,8 +34,10 @@ defmodule Pleroma.Web.MastodonAPI.PollController do
with %Object{} = object <- Object.get_by_id(id), with %Object{} = object <- Object.get_by_id(id),
%Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]), %Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]),
true <- Visibility.visible_for_user?(activity, user) do true <- Visibility.visible_for_user?(activity, user) do
PollWorker.new(%{"op" => "refresh", "activity_id" => activity.id}) unless activity.local do
|> Oban.insert(unique: [period: 60]) PollWorker.new(%{"op" => "refresh", "activity_id" => activity.id})
|> Oban.insert(unique: [period: 60])
end
try_render(conn, "show.json", %{object: object, for: user}) try_render(conn, "show.json", %{object: object, for: user})
else else

View file

@ -29,6 +29,25 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
id = to_string(object.id) id = to_string(object.id)
assert %{"id" => ^id, "expired" => false, "multiple" => false} = response assert %{"id" => ^id, "expired" => false, "multiple" => false} = response
refute_enqueued(
worker: Pleroma.Workers.PollWorker,
args: %{"op" => "refresh", "activity_id" => activity.id}
)
end
test "does not create oban job to refresh poll if activity is local", %{conn: conn} do
user = insert(:user, local: false)
question = insert(:question, user: user)
activity = insert(:question_activity, question: question, local: false)
# Ensure this is not represented as a local activity
refute activity.local
object = Object.normalize(activity, fetch: false)
get(conn, "/api/v1/polls/#{object.id}")
|> json_response_and_validate_schema(200)
assert_enqueued( assert_enqueued(
worker: Pleroma.Workers.PollWorker, worker: Pleroma.Workers.PollWorker,
args: %{"op" => "refresh", "activity_id" => activity.id} args: %{"op" => "refresh", "activity_id" => activity.id}