1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-11 09:32:51 +00:00

cache character end point - update reply count/thread reply id

This commit is contained in:
2018-01-09 23:24:09 -06:00
parent 2d6ff0875f
commit d3d3bef9a5
17 changed files with 226 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
defmodule MyApp.Data.Reply do
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query
alias MyApp.Repo
alias MyApp.Data
@@ -35,6 +36,20 @@ defmodule MyApp.Data.Reply do
insert_changeset(%Data.Reply{}, params)
|> Repo.insert
|> Data.Util.process_insert_or_update
|> update_thread_new_reply
end
defp update_thread_new_reply({:error, error}), do: {:error, error}
defp update_thread_new_reply({:ok, reply}) do
thread_id = Map.get(reply, :thread_id)
user_id = Map.get(reply, :user_id)
query = from t in Data.Thread, where: t.id == ^thread_id,
update: [set: [last_reply_id: ^user_id], inc: [reply_count: 1]]
case Repo.update_all(query, []) do
nil -> {:error, "update thread error"}
_ -> {:ok, reply}
end
end
@spec user_update(map) :: {:ok, map} | {:error, map}