summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2023-01-13 21:07:00 -0700
committerSimponic <loganhunt@simponic.xyz>2023-01-13 21:07:00 -0700
commita607da7918f1611a503d1e0e566883bc352c406e (patch)
treeba8d50adafb8b3585eb2fea7de0e27f8153db867 /lib
parentea51b89dc611bd747044d4773865fa1f6c15fcd8 (diff)
downloadchessh-a607da7918f1611a503d1e0e566883bc352c406e.tar.gz
chessh-a607da7918f1611a503d1e0e566883bc352c406e.zip
Decrease burst ms again, fix insertion error with player session when using public key
Diffstat (limited to 'lib')
-rw-r--r--lib/chessh/schema/player_session.ex19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/chessh/schema/player_session.ex b/lib/chessh/schema/player_session.ex
index 8ca338c..b16519f 100644
--- a/lib/chessh/schema/player_session.ex
+++ b/lib/chessh/schema/player_session.ex
@@ -14,7 +14,7 @@ defmodule Chessh.PlayerSession do
def changeset(player_session, attrs) do
player_session
- |> cast(attrs, [:login])
+ |> cast(attrs, [:login, :node_id, :process])
end
def concurrent_sessions(player) do
@@ -58,12 +58,17 @@ defmodule Chessh.PlayerSession do
"Creating session for player #{username} on node #{System.fetch_env!("NODE_ID")} with process #{inspect(self())}"
)
- Repo.insert(%PlayerSession{
- login: DateTime.utc_now(),
- node_id: System.fetch_env!("NODE_ID"),
- player: player,
- process: Utils.pid_to_str(self())
- })
+ now = DateTime.utc_now()
+
+ Repo.insert!(
+ %PlayerSession{
+ login: now,
+ node_id: System.fetch_env!("NODE_ID"),
+ player: player,
+ process: Utils.pid_to_str(self())
+ },
+ on_conflict: :nothing
+ )
concurrent_sessions = PlayerSession.concurrent_sessions(player)