Remove Dataloader related code from Mobilizon context

This commit is contained in:
miffigriffi 2019-09-18 00:18:45 +02:00
parent 48dbec51f5
commit eaff073cd2
7 changed files with 9 additions and 53 deletions

View File

@ -48,14 +48,6 @@ defmodule Mobilizon.Actors do
@public_visibility [:public, :unlisted] @public_visibility [:public, :unlisted]
@administrator_roles [:creator, :administrator] @administrator_roles [:creator, :administrator]
@doc false
@spec data :: Dataloader.Ecto.t()
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
@doc false
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
def query(queryable, _params), do: queryable
@doc """ @doc """
Gets a single actor. Gets a single actor.
""" """

View File

@ -10,14 +10,6 @@ defmodule Mobilizon.Addresses do
require Logger require Logger
@doc false
@spec data :: Dataloader.Ecto.t()
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
@doc false
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
def query(queryable, _params), do: queryable
@doc """ @doc """
Gets a single address. Gets a single address.
""" """

View File

@ -90,14 +90,6 @@ defmodule Mobilizon.Events do
@comment_preloads [:actor, :attributed_to, :in_reply_to_comment] @comment_preloads [:actor, :attributed_to, :in_reply_to_comment]
@doc false
@spec data :: Dataloader.Ecto.t()
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
@doc false
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
def query(queryable, _params), do: queryable
@doc """ @doc """
Gets a single event. Gets a single event.
""" """

View File

@ -10,14 +10,6 @@ defmodule Mobilizon.Media do
alias Mobilizon.Media.{File, Picture} alias Mobilizon.Media.{File, Picture}
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
@doc false
@spec data :: Dataloader.Ecto.t()
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
@doc false
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
def query(queryable, _params), do: queryable
@doc """ @doc """
Gets a single picture. Gets a single picture.
""" """

View File

@ -13,14 +13,6 @@ defmodule Mobilizon.Reports do
defenum(ReportStatus, :report_status, [:open, :closed, :resolved]) defenum(ReportStatus, :report_status, [:open, :closed, :resolved])
@doc false
@spec data :: Dataloader.Ecto.t()
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
@doc false
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
def query(queryable, _params), do: queryable
@doc """ @doc """
Gets a single report. Gets a single report.
""" """

View File

@ -20,14 +20,6 @@ defmodule Mobilizon.Users do
defenum(UserRole, :user_role, [:administrator, :moderator, :user]) defenum(UserRole, :user_role, [:administrator, :moderator, :user])
@doc false
@spec data :: Dataloader.Ecto.t()
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
@doc false
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
def query(queryable, _params), do: queryable
@doc """ @doc """
Registers an user. Registers an user.
""" """

View File

@ -7,6 +7,7 @@ defmodule MobilizonWeb.Schema do
alias Mobilizon.{Actors, Events, Users, Addresses, Media} alias Mobilizon.{Actors, Events, Users, Addresses, Media}
alias Mobilizon.Actors.{Actor, Follower, Member} alias Mobilizon.Actors.{Actor, Follower, Member}
alias Mobilizon.Events.{Event, Comment, Participant} alias Mobilizon.Events.{Event, Comment, Participant}
alias Mobilizon.Storage.Repo
import_types(MobilizonWeb.Schema.Custom.UUID) import_types(MobilizonWeb.Schema.Custom.UUID)
import_types(MobilizonWeb.Schema.Custom.Point) import_types(MobilizonWeb.Schema.Custom.Point)
@ -87,13 +88,16 @@ defmodule MobilizonWeb.Schema do
end end
def context(ctx) do def context(ctx) do
default_query = fn queryable, _params -> queryable end
default_source = Dataloader.Ecto.new(Repo, query: default_query)
loader = loader =
Dataloader.new() Dataloader.new()
|> Dataloader.add_source(Actors, Actors.data()) |> Dataloader.add_source(Actors, default_source)
|> Dataloader.add_source(Users, Users.data()) |> Dataloader.add_source(Users, default_source)
|> Dataloader.add_source(Events, Events.data()) |> Dataloader.add_source(Events, default_source)
|> Dataloader.add_source(Addresses, Addresses.data()) |> Dataloader.add_source(Addresses, default_source)
|> Dataloader.add_source(Media, Media.data()) |> Dataloader.add_source(Media, default_source)
Map.put(ctx, :loader, loader) Map.put(ctx, :loader, loader)
end end