diff options
author | lain <lain@soykaf.club> | 2019-02-09 22:01:08 +0100 |
---|---|---|
committer | lain <lain@soykaf.club> | 2019-02-09 22:01:08 +0100 |
commit | f8388be9c69981958e9a96dce68fc39bdedb5cd3 (patch) | |
tree | 52c4bc943eaab9bd4a4e8ea700dd1b71299bad33 /lib/pleroma/web | |
parent | 99fd199bda8bd90cd3e8c69d54087531ddc02eac (diff) | |
download | pleroma-f8388be9c69981958e9a96dce68fc39bdedb5cd3.tar.gz |
Do object insertion through Cachex
So we don't flood our postgres logs with errors. Should also make things
slightly faster.
Diffstat (limited to 'lib/pleroma/web')
-rw-r--r-- | lib/pleroma/web/activity_pub/utils.ex | 10 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api.ex | 12 |
2 files changed, 4 insertions, 18 deletions
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 4a2cc6738..134701e80 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -134,14 +134,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do context = context || generate_id("contexts") changeset = Object.context_mapping(context) - case Repo.insert(changeset) do - {:ok, object} -> - object - - # This should be solved by an upsert, but it seems ecto - # has problems accessing the constraint inside the jsonb. - {:error, _} -> - Object.get_cached_by_ap_id(context) + with {:ok, object} <- Object.insert_or_get(changeset) do + object end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 7d00c01a1..ddd5c5cfb 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -305,16 +305,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do else _e -> changeset = Object.context_mapping(context) - - case Repo.insert(changeset) do - {:ok, %{id: id}} -> - id - - # This should be solved by an upsert, but it seems ecto - # has problems accessing the constraint inside the jsonb. - {:error, _} -> - Object.get_cached_by_ap_id(context).id - end + {:ok, object} = Object.insert_or_get(changeset) + object.id end end |