Set sum types in query
authorRoman Chvanikov <chvanikoff@pm.me>
Sun, 10 May 2020 06:13:24 +0000 (09:13 +0300)
committerRoman Chvanikov <chvanikoff@pm.me>
Sun, 10 May 2020 06:13:24 +0000 (09:13 +0300)
lib/pleroma/counter_cache.ex

index aa6d38687d3481267a1a1e037f9bb3eeb75797e3..ebd1f603df4c5f7d650a1f5576162f791fb1535a 100644 (file)
@@ -43,16 +43,12 @@ defmodule Pleroma.CounterCache do
   def get_sum do
     CounterCache
     |> select([c], %{
-      "public" => sum(c.public),
-      "unlisted" => sum(c.unlisted),
-      "private" => sum(c.private),
-      "direct" => sum(c.direct)
+      "public" => type(sum(c.public), :integer),
+      "unlisted" => type(sum(c.unlisted), :integer),
+      "private" => type(sum(c.private), :integer),
+      "direct" => type(sum(c.direct), :integer)
     })
     |> Repo.one()
-    |> Enum.map(fn {visibility, dec_count} ->
-      {visibility, Decimal.to_integer(dec_count)}
-    end)
-    |> Enum.into(%{})
   end
 
   def set(instance, values) do