Skip to content

Commit

Permalink
chore: Fix linter issues & deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Jul 17, 2024
1 parent c7efee0 commit 16c9eda
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 67 deletions.
12 changes: 11 additions & 1 deletion apps/cf/lib/accounts/username_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ defmodule CF.Accounts.UsernameGenerator do
@name __MODULE__
@username_prefix "NewUser-"

def start_link do
def child_spec(opts) do
%{
id: __MODULE__,
start: {__MODULE__, :start_link, [opts]},
type: :worker,
restart: :permanent,
shutdown: 500
}
end

def start_link(_opts \\ []) do
Agent.start_link(
fn ->
Hashids.new(
Expand Down
6 changes: 3 additions & 3 deletions apps/cf/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ defmodule CF.Application do
# Define workers and child supervisors to be supervised
children = [
# Other custom supervisors
supervisor(CF.Sources.Fetcher, []),
{CF.Sources.Fetcher, []},
# Misc workers
worker(CF.Accounts.UsernameGenerator, []),
{CF.Accounts.UsernameGenerator, []},
# Sweep tokens from db
worker(Guardian.DB.Token.SweeperServer, [])
{Guardian.DB.Token.SweeperServer, []}
]

# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
Expand Down
23 changes: 1 addition & 22 deletions apps/cf/lib/errors/errors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,9 @@ defmodule CF.Errors do
end

@spec do_report(:error | :exit | :throw, any(), [any()], cf_error_params()) :: :ok
def do_report(type, value, stacktrace, params) do
def do_report(type, value, stacktrace, _params) do
# Any call to Sentry, Rollbar, etc. should be done here
Logger.error("[ERROR][#{type}] #{inspect(value)} - #{inspect(stacktrace)}")
:ok
end

defp build_occurence_data(params) do
default_occurrence_data()
|> add_user(params[:user])
|> Map.merge(params[:data] || %{})
end

defp default_occurrence_data() do
%{
"code_version" => CF.Application.version()
}
end

defp add_user(base, nil),
do: base

defp add_user(base, %{id: id, username: username}),
do: Map.merge(base, %{"person" => %{"id" => Integer.to_string(id), "username" => username}})

defp add_user(base, %{id: id}),
do: Map.merge(base, %{"person" => %{"id" => Integer.to_string(id)}})
end
4 changes: 1 addition & 3 deletions apps/cf/lib/llms/statements_creator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ defmodule CF.LLMs.StatementsCreator do
end
end

@doc """
Chunk captions everytime we reach the max caption length
"""
# Chunk captions each time we reach the max caption length
defp chunk_captions(captions) do
# TODO: Add last captions from previous batch to preserve context
Enum.chunk_every(captions, @captions_chunk_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"title": "<%= video.id %>"
},
"captions": <%= captions |> Enum.map(fn caption -> %{
"start": floor(caption["start"]),
"text": String.trim(caption["text"])
start: floor(caption["start"]),
text: String.trim(caption["text"])
} end) |> Jason.encode! %>
}
```
12 changes: 11 additions & 1 deletion apps/cf/lib/sources/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ defmodule CF.Sources.Fetcher do

# ---- Public API ----

def start_link() do
def child_spec(opts) do
%{
id: __MODULE__,
start: {__MODULE__, :start_link, [opts]},
type: :worker,
restart: :permanent,
shutdown: 500
}
end

def start_link(_opts \\ []) do
import Supervisor.Spec

Supervisor.start_link(
Expand Down
8 changes: 1 addition & 7 deletions apps/cf_atom_feed/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ defmodule CF.AtomFeed.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec

children = []
config = Application.get_env(:cf_atom_feed, CF.AtomFeed.Router)

if config[:cowboy] do
children = [supervisor(CF.AtomFeed.Router, []) | children]
end
children = if config[:cowboy], do: [{CF.AtomFeed.Router, []}], else: []

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
Expand Down
12 changes: 11 additions & 1 deletion apps/cf_atom_feed/lib/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ defmodule CF.AtomFeed.Router do
plug(:match)
plug(:dispatch)

def start_link do
def child_spec(opts) do
%{
id: __MODULE__,
start: {__MODULE__, :start_link, [opts]},
type: :worker,
restart: :permanent,
shutdown: 500
}
end

def start_link(_opts \\ []) do
config = Application.get_env(:cf_atom_feed, CF.AtomFeed.Router)
Logger.info("Running CF.AtomFeed.Router with cowboy on port #{config[:cowboy][:port]}")
Plug.Cowboy.http(CF.AtomFeed.Router, [], config[:cowboy])
Expand Down
2 changes: 1 addition & 1 deletion apps/cf_graphql/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule CF.Graphql.Application do
# Start the PubSub system
{Phoenix.PubSub, name: CF.Graphql.PubSub},
# Start the endpoint when the application starts
supervisor(CF.GraphQLWeb.Endpoint, [])
{CF.GraphQLWeb.Endpoint, []}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
4 changes: 2 additions & 2 deletions apps/cf_rest_api/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ defmodule CF.RestApi.Application do
# Start the PubSub system
{Phoenix.PubSub, name: CF.RestApi.PubSub},
# Start the endpoint when the application starts
supervisor(CF.RestApi.Endpoint, []),
{CF.RestApi.Endpoint, []},
# Presence to track number of connected users to a channel
supervisor(CF.RestApi.Presence, [])
{CF.RestApi.Presence, []}
]

# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
Expand Down
13 changes: 7 additions & 6 deletions apps/cf_reverse_proxy/lib/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ defmodule CF.ReverseProxy.Plug do
)

@default_host CF.RestApi.Endpoint
@base_host_regex ~r/^(?<service>rest|graphql|feed)\./
@subdomains %{
"graphql" => CF.GraphQLWeb.Endpoint,
"rest" => CF.RestApi.Endpoint,
"feed" => CF.AtomFeed.Router
}

def init(opts), do: opts

Expand All @@ -26,6 +20,13 @@ defmodule CF.ReverseProxy.Plug do
# https://github.com/jesseshieh/master_proxy

if Application.get_env(:cf, :env) == :dev do
@base_host_regex ~r/^(?<service>rest|graphql|feed)\./
@subdomains %{
"graphql" => CF.GraphQLWeb.Endpoint,
"rest" => CF.RestApi.Endpoint,
"feed" => CF.AtomFeed.Router
}

# Dev requests are routed through here
def call(conn, _) do
if conn.request_path == "/status" do
Expand Down
4 changes: 1 addition & 3 deletions apps/db/lib/db/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ defmodule DB.Application do

# Define workers and child supervisors to be supervised
children = [
# Starts a worker by calling: DB.Worker.start_link(arg1, arg2, arg3)
# worker(DB.Worker, [arg1, arg2, arg3]),
supervisor(DB.Repo, [])
{DB.Repo, []}
]

# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
Expand Down
2 changes: 1 addition & 1 deletion apps/db/lib/db_schema/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule DB.Schema.Source do
end

defp validate_file_mime_type(:file_mime_type, mime_type) do
if MIME.valid?(mime_type) do
if MIME.extensions(mime_type) != [] do
[]
else
[file_mime_type: "Invalid MIME type"]
Expand Down
9 changes: 0 additions & 9 deletions apps/db/lib/db_schema/video.ex
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,4 @@ defmodule DB.Schema.Video do
)
end)
end

# Return IDs of videos with at least 3 statements
defp popular_videos_subquery do
Video
|> join(:inner, [v], s in assoc(v, :statements))
|> select([:id])
|> group_by([v], v.id)
|> having([v, s], count(s.id) >= 3)
end
end
3 changes: 3 additions & 0 deletions apps/db/lib/db_type/flag_reason.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ defmodule DB.Type.FlagReason do
|> Enum.find(fn {_, id} -> id == reason_id end)
|> elem(0)
end

# Implement the embed_as/1 function required by the Ecto.Type behaviour
def embed_as(_), do: :dump
end
3 changes: 2 additions & 1 deletion apps/db/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ defmodule DB.Mixfile do
{:burnex, "~> 3.1"},
{:hashids, "~> 2.0"},
{:kaur, "~> 1.1"},
{:mime, "~> 1.2"},
{:mime, "~> 2.0.6"},
{:scrivener_ecto, "~> 2.0"},
{:algoliax, "~> 0.7.1"},
{:httpoison, "~> 2.2"},

# Dev only
{:exsync, "~> 0.2", only: :dev},
Expand Down
2 changes: 1 addition & 1 deletion apps/db/test/db_schema/speaker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule DB.Schema.SpeakerTest do
alias DB.Schema.Speaker

@valid_attrs %{
full_name: "#{Faker.Name.first_name()} #{Faker.Name.last_name()}",
full_name: "#{Faker.Person.first_name()} #{Faker.Person.last_name()}",
wikidata_item_id: nil
}
@invalid_attrs %{}
Expand Down
6 changes: 3 additions & 3 deletions apps/db/test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule DB.Factory do

def user_factory do
%User{
name: Faker.Name.first_name(),
name: Faker.Person.first_name(),
username: "User-#{random_string(10)}",
email: Faker.Internet.email(),
encrypted_password: "$2b$12$fe55IfCdqNzKp1wMIJDwVeG3f7guOduEE5HS2C9IJyfkuk3avbjQG",
Expand Down Expand Up @@ -65,8 +65,8 @@ defmodule DB.Factory do

def speaker_factory do
%Speaker{
full_name: Faker.Name.name(),
title: Faker.Name.title(),
full_name: Faker.Person.name(),
title: Faker.Person.title(),
country: Faker.Address.country_code()
}
end
Expand Down

0 comments on commit 16c9eda

Please sign in to comment.