1 defmodule Mix.Tasks.Pleroma.Marker do
7 alias Pleroma.Notification
9 def run(["update_markers"]) do
12 from(q in Notification,
14 timeline: "notifications",
16 unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
18 type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
23 |> Enum.each(fn attrs ->
26 |> Ecto.Changeset.change()
27 |> Pleroma.Repo.insert(
29 on_conflict: {:replace, [:last_read_id, :unread_count]},
30 conflict_target: [:user_id, :timeline]