Object Fetcher: set cache after reinjecting
authorrinpatch <rinpatch@sdf.org>
Wed, 6 Nov 2019 11:00:03 +0000 (14:00 +0300)
committerrinpatch <rinpatch@sdf.org>
Fri, 8 Nov 2019 19:47:08 +0000 (22:47 +0300)
Probably fixes the issue hj had, where polls would have different
counters between endpoints.

lib/pleroma/object/fetcher.ex
test/object_test.exs

index cea33b5af26e9ef3a56b12f688ca63a6de0c5a52..76f79f45d2c436f6ff69d4bfe741ef518e5cea30 100644 (file)
@@ -38,7 +38,8 @@ defmodule Pleroma.Object.Fetcher do
          data <- maybe_reinject_internal_fields(data, struct),
          changeset <- Object.change(struct, %{data: data}),
          changeset <- touch_changeset(changeset),
-         {:ok, object} <- Repo.insert_or_update(changeset) do
+         {:ok, object} <- Repo.insert_or_update(changeset),
+         {:ok, object} <- Object.set_cache(object) do
       {:ok, object}
     else
       e ->
index 3d64fdb49d82d9e494db00524f5791c57c7e0cf5..bf651f4fbb96abb3fb9207de407bd8405d8800f0 100644 (file)
@@ -124,6 +124,8 @@ defmodule Pleroma.ObjectTest do
       %Object{} =
         object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
 
+      Object.set_cache(object)
+
       assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
       assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
 
@@ -133,6 +135,8 @@ defmodule Pleroma.ObjectTest do
       })
 
       updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
+      object_in_cache = Object.get_cached_by_ap_id(object.data["id"])
+      assert updated_object == object_in_cache
       assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 8
       assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 3
     end
@@ -141,6 +145,8 @@ defmodule Pleroma.ObjectTest do
       %Object{} =
         object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
 
+      Object.set_cache(object)
+
       assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
       assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
 
@@ -148,6 +154,8 @@ defmodule Pleroma.ObjectTest do
                mock_modified.(%Tesla.Env{status: 404, body: ""})
 
                updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
+               object_in_cache = Object.get_cached_by_ap_id(object.data["id"])
+               assert updated_object == object_in_cache
                assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
                assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
              end) =~
@@ -160,6 +168,8 @@ defmodule Pleroma.ObjectTest do
       %Object{} =
         object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
 
+      Object.set_cache(object)
+
       assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
       assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
 
@@ -169,6 +179,8 @@ defmodule Pleroma.ObjectTest do
       })
 
       updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: 100)
+      object_in_cache = Object.get_cached_by_ap_id(object.data["id"])
+      assert updated_object == object_in_cache
       assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
       assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
     end
@@ -177,6 +189,8 @@ defmodule Pleroma.ObjectTest do
       %Object{} =
         object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
 
+      Object.set_cache(object)
+
       assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
       assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
 
@@ -192,6 +206,8 @@ defmodule Pleroma.ObjectTest do
       })
 
       updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
+      object_in_cache = Object.get_cached_by_ap_id(object.data["id"])
+      assert updated_object == object_in_cache
       assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 8
       assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 3