Check if a refresh is permitted by comparing timestamps before attempting to insert an Oban job

It's better to avoid inserting an Oban job that will just be rejected if it's not expensive to check.
This commit is contained in:
Mark Felder 2024-10-03 10:14:02 -04:00
commit ba2ae5e40b
3 changed files with 16 additions and 9 deletions

View file

@ -29,13 +29,16 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
id = to_string(object.id)
assert %{"id" => ^id, "expired" => false, "multiple" => false} = response
# Local activities should not generate an Oban job to refresh
assert activity.local
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
test "creates an oban job to refresh poll if activity is remote", %{conn: conn} do
user = insert(:user, local: false)
question = insert(:question, user: user)
activity = insert(:question_activity, question: question, local: false)