remove old match repo
Some checks failed
ci / docker (push) Failing after 3m58s

This commit is contained in:
Álvaro 2024-06-23 12:59:05 +02:00
parent 305b9237c8
commit e364b20b1b
5 changed files with 8 additions and 68 deletions

View File

@ -33,6 +33,13 @@ defmodule LolAnalytics.Dimensions.Match.MatchRepo do
end end
end end
@spec get(String.t()) :: nil | %MatchSchema{}
def get(match_id) do
query = from m in MatchSchema, where: m.match_id == ^match_id
Repo.one(query)
end
@type update_attrs :: %{ @type update_attrs :: %{
optional(:fact_champion_played_game_status) => process_status(), optional(:fact_champion_played_game_status) => process_status(),
optional(:fact_champion_picked_item_status) => process_status(), optional(:fact_champion_picked_item_status) => process_status(),

View File

@ -1,35 +0,0 @@
defmodule LolAnalytics.Match.MatchRepo do
alias LolAnalytics.Match.MatchSchema
import Ecto.Query
def list_matches do
query = from m in MatchSchema, order_by: [desc: m.match_id]
LoLAnalytics.Repo.all(query)
end
def number_of_matches do
query = from m in MatchSchema, select: count(m.match_id)
LoLAnalytics.Repo.one(query)
end
@spec get_match(String.t()) :: %LolAnalytics.Match.MatchSchema{} | nil
def get_match(match_id) do
query = from m in MatchSchema, where: m.match_id == ^match_id
LoLAnalytics.Repo.one(query)
end
@spec insert_match(String.t()) :: %LolAnalytics.Match.MatchSchema{}
def insert_match(match_id) do
MatchSchema.changeset(%MatchSchema{}, %{:match_id => match_id, :processed => false})
|> LoLAnalytics.Repo.insert()
end
@spec update_match(%LolAnalytics.Match.MatchSchema{}, term()) ::
%LolAnalytics.Match.MatchSchema{}
def update_match(match, attrs) do
match = MatchSchema.changeset(match, attrs)
LoLAnalytics.Repo.update(match)
end
end

View File

@ -1,19 +0,0 @@
defmodule LolAnalytics.Match.MatchSchema do
use Ecto.Schema
import Ecto.Changeset
schema "match" do
field :match_id, :string
field :processed, :boolean, default: false
field :match_url, :string
timestamps()
end
def changeset(%__MODULE__{} = match, params \\ %{}) do
match
|> cast(params, [:match_id, :processed, :match_url])
|> validate_required([:match_id, :processed])
end
end

View File

@ -69,19 +69,6 @@ defmodule Scrapper.Consumer.MatchConsumer do
Storage.MatchStorage.S3MatchStorage.store_match(match_id, raw_match, "matches") Storage.MatchStorage.S3MatchStorage.store_match(match_id, raw_match, "matches")
end end
match = LolAnalytics.Match.MatchRepo.get_match(match_id)
case match do
nil ->
LolAnalytics.Match.MatchRepo.insert_match(match_id)
_ ->
LolAnalytics.Match.MatchRepo.update_match(match, %{
:processed => true,
:match_url => match_url
})
end
decoded_match.metadata.participants decoded_match.metadata.participants
# |> Enum.shuffle() # |> Enum.shuffle()
# |> Enum.take(2) # |> Enum.take(2)

View File

@ -16,7 +16,7 @@ defmodule Scrapper.Queue.MatchQueue do
@spec enqueue_match(String.t()) :: any() @spec enqueue_match(String.t()) :: any()
def enqueue_match(match_id) do def enqueue_match(match_id) do
LolAnalytics.Match.MatchRepo.get_match(match_id) LolAnalytics.Dimensions.Match.MatchRepo.get(match_id)
|> case do |> case do
nil -> GenServer.call(__MODULE__, {:enqueue_match, match_id}) nil -> GenServer.call(__MODULE__, {:enqueue_match, match_id})
_match -> :already_processed _match -> :already_processed