Don't mess with the cache on metadata update
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Tue, 8 Nov 2022 10:39:01 +0000 (10:39 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Tue, 8 Nov 2022 10:39:01 +0000 (10:39 +0000)
lib/pleroma/application.ex
lib/pleroma/instances/instance.ex
test/pleroma/instances/instance_test.exs
test/pleroma/web/admin_api/views/report_view_test.exs

index a78924dfabd48838c6bf25186bb39be1bdf7cde3..b9bcad40cfaffdca23e224638bb55b94f9ffd68e 100644 (file)
@@ -157,7 +157,7 @@ defmodule Pleroma.Application do
       build_cachex("failed_proxy_url", limit: 2500),
       build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000),
       build_cachex("translations", default_ttl: :timer.hours(24 * 30), limit: 2500),
-      build_cachex("instances", default_ttl: :timer.hours(24), limit: 2500)
+      build_cachex("instances", default_ttl: :timer.hours(24), ttl_interval: 1000, limit: 2500)
     ]
   end
 
index fcf3181bf530550cb18120a6b873b0772f6b67db..5ee408f21ea77e7a4dafbd12f4e5bf8b2b601952 100644 (file)
@@ -176,17 +176,14 @@ defmodule Pleroma.Instances.Instance do
         favicon = scrape_favicon(uri)
         nodeinfo = scrape_nodeinfo(uri)
 
-        {:ok, instance} =
-          existing_record
-          |> changeset(%{
-            host: host,
-            favicon: favicon,
-            nodeinfo: nodeinfo,
-            metadata_updated_at: NaiveDateTime.utc_now()
-          })
-          |> Repo.update()
-
-        @cachex.put(:instances_cache, "instances:#{host}", instance)
+        existing_record
+        |> changeset(%{
+          host: host,
+          favicon: favicon,
+          nodeinfo: nodeinfo,
+          metadata_updated_at: NaiveDateTime.utc_now()
+        })
+        |> Repo.update()
       else
         {:discard, "Does not require update"}
       end
@@ -205,8 +202,6 @@ defmodule Pleroma.Instances.Instance do
           metadata_updated_at: NaiveDateTime.utc_now()
         })
         |> Repo.insert()
-
-      @cachex.put(:instances_cache, "instances:#{host}", instance)
     end
   end
 
index adc847da5bcc791513755d753da087a7d1623f24..6ec55c7b7383b70993dc956da9471fd0248dcf13 100644 (file)
@@ -136,7 +136,7 @@ defmodule Pleroma.Instances.InstanceTest do
           }
       end)
 
-      assert {:ok, true} ==
+      assert {:ok, %Instance{host: "favicon.example.org"}} =
                Instance.update_metadata(URI.parse("https://favicon.example.org/"))
 
       {:ok, instance} = Instance.get_cached_by_url("https://favicon.example.org/")
@@ -177,7 +177,7 @@ defmodule Pleroma.Instances.InstanceTest do
           }
       end)
 
-      assert {:ok, true} ==
+      assert {:ok, %Instance{host: "long-favicon.example.org"}} =
                Instance.update_metadata(URI.parse("https://long-favicon.example.org/"))
 
       {:ok, instance} = Instance.get_cached_by_url("https://long-favicon.example.org/")
@@ -214,7 +214,7 @@ defmodule Pleroma.Instances.InstanceTest do
       end)
 
       refute capture_log(fn ->
-               assert {:ok, true} =
+               assert {:ok, %Instance{host: "no-favicon.example.org"}} =
                         Instance.update_metadata(URI.parse("https://no-favicon.example.org/"))
              end) =~ "Instance.update_metadata(\"https://no-favicon.example.org/\") error: "
     end
@@ -241,7 +241,7 @@ defmodule Pleroma.Instances.InstanceTest do
           }
       end)
 
-      assert {:ok, true} ==
+      assert {:ok, %Instance{host: "bad-nodeinfo.example.org"}} =
                Instance.update_metadata(URI.parse("https://bad-nodeinfo.example.org/"))
 
       {:ok, instance} = Instance.get_cached_by_url("https://bad-nodeinfo.example.org/")
@@ -277,7 +277,7 @@ defmodule Pleroma.Instances.InstanceTest do
           }
       end)
 
-      assert {:ok, true} ==
+      assert {:ok, %Instance{host: "bad-nodeinfo.example.org"}} =
                Instance.update_metadata(URI.parse("https://bad-nodeinfo.example.org/"))
 
       {:ok, instance} = Instance.get_cached_by_url("https://bad-nodeinfo.example.org/")
@@ -315,7 +315,7 @@ defmodule Pleroma.Instances.InstanceTest do
           }
       end)
 
-      assert {:ok, true} ==
+      assert {:ok, %Instance{host: "bad-nodeinfo.example.org"}} =
                Instance.update_metadata(URI.parse("https://bad-nodeinfo.example.org/"))
 
       {:ok, instance} = Instance.get_cached_by_url("https://bad-nodeinfo.example.org/")
index 093e2d95dd24f1c2ee56e09de0ba822d99a7d10f..1c115528a550176f207412b81cac281c8640fe3d 100644 (file)
@@ -45,7 +45,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
       ReportView.render("show.json", Report.extract_report_info(activity))
       |> Map.delete(:created_at)
 
-    assert result == expected
+    assert Jason.encode!(result) == Jason.encode!(expected)
   end
 
   test "includes reported statuses" do