Merge branch 'develop' into dtluna/pleroma-feature/unfollow-activity
[akkoma] / lib / pleroma / object.ex
1 defmodule Pleroma.Object do
2 use Ecto.Schema
3 alias Pleroma.{Repo, Object}
4 import Ecto.Query
5
6 schema "objects" do
7 field :data, :map
8
9 timestamps()
10 end
11
12 def get_by_ap_id(ap_id) do
13 Repo.one(from object in Object,
14 where: fragment("? @> ?", object.data, ^%{id: ap_id}))
15 end
16
17 def get_cached_by_ap_id(ap_id) do
18 if Mix.env == :test do
19 get_by_ap_id(ap_id)
20 else
21 key = "object:#{ap_id}"
22 Cachex.get!(:user_cache, key, fallback: fn(_) ->
23 object = get_by_ap_id(ap_id)
24 if object do
25 {:commit, object}
26 else
27 {:ignore, object}
28 end
29 end)
30 end
31 end
32
33 def context_mapping(context) do
34 %Object{data: %{"id" => context}}
35 end
36 end