Format the code.
This commit is contained in:
parent
480932c8e5
commit
4afbef39f4
111 changed files with 4912 additions and 2769 deletions
|
|
@ -4,14 +4,14 @@ defmodule Pleroma.Object do
|
|||
import Ecto.{Query, Changeset}
|
||||
|
||||
schema "objects" do
|
||||
field :data, :map
|
||||
field(:data, :map)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def create(data) do
|
||||
Object.change(%Object{}, %{data: data})
|
||||
|> Repo.insert
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
def change(struct, params \\ %{}) do
|
||||
|
|
@ -22,24 +22,30 @@ defmodule Pleroma.Object do
|
|||
end
|
||||
|
||||
def get_by_ap_id(nil), do: nil
|
||||
|
||||
def get_by_ap_id(ap_id) do
|
||||
Repo.one(from object in Object,
|
||||
where: fragment("(?)->>'id' = ?", object.data, ^ap_id))
|
||||
Repo.one(from(object in Object, where: fragment("(?)->>'id' = ?", object.data, ^ap_id)))
|
||||
end
|
||||
|
||||
def get_cached_by_ap_id(ap_id) do
|
||||
if Mix.env == :test do
|
||||
if Mix.env() == :test do
|
||||
get_by_ap_id(ap_id)
|
||||
else
|
||||
key = "object:#{ap_id}"
|
||||
Cachex.get!(:user_cache, key, fallback: fn(_) ->
|
||||
object = get_by_ap_id(ap_id)
|
||||
if object do
|
||||
{:commit, object}
|
||||
else
|
||||
{:ignore, object}
|
||||
|
||||
Cachex.get!(
|
||||
:user_cache,
|
||||
key,
|
||||
fallback: fn _ ->
|
||||
object = get_by_ap_id(ap_id)
|
||||
|
||||
if object do
|
||||
{:commit, object}
|
||||
else
|
||||
{:ignore, object}
|
||||
end
|
||||
end
|
||||
end)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue