Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85802788
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/pleroma/repo.ex b/lib/pleroma/repo.ex
index eb86b10fd..58d918cb9 100644
--- a/lib/pleroma/repo.ex
+++ b/lib/pleroma/repo.ex
@@ -1,33 +1,41 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo do
use Ecto.Repo,
otp_app: :pleroma,
adapter: Ecto.Adapters.Postgres,
migration_timestamps: [type: :naive_datetime_usec]
defmodule Instrumenter do
use Prometheus.EctoInstrumenter
end
@doc """
Dynamically loads the repository url from the
DATABASE_URL environment variable.
"""
def init(_, opts) do
{:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
end
@doc """
Gets association from cache or loads if need
"""
@spec get_assoc(struct(), atom()) :: {:ok, struct()} | {:error, :not_found}
def get_assoc(model, association) do
+ case Map.get(model, association) do
+ %Ecto.Association.NotLoaded{} -> load_assoc(model, association)
+ nil -> {:error, :not_found}
+ assoc -> {:ok, assoc}
+ end
+ end
+
+ defp load_assoc(model, association) do
case __MODULE__.one(Ecto.assoc(model, association)) do
nil -> {:error, :not_found}
association -> {:ok, association}
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Oct 8, 7:04 PM (10 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1784229
Default Alt Text
(1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment