summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/config.exs2
-rw-r--r--lib/chessh/schema/player_session.ex19
2 files changed, 13 insertions, 8 deletions
diff --git a/config/config.exs b/config/config.exs
index 2e20647..ad54ebf 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -15,7 +15,7 @@ config :chessh, RateLimits,
jail_timeout_ms: 5 * 60 * 1000,
jail_attempt_threshold: 15,
max_concurrent_user_sessions: 5,
- player_session_message_burst_ms: 1_000,
+ player_session_message_burst_ms: 500,
player_session_message_burst_rate: 8
import_config "#{config_env()}.exs"
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)