Skip to content

Commit 95e30ce

Browse files
committed
Minor optimizations
1 parent 6c30fce commit 95e30ce

File tree

8 files changed

+55
-24
lines changed

8 files changed

+55
-24
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ services:
3939
environment:
4040
POSTGRES_USER: ${CODEBATTLE_DB_USERNAME}
4141
POSTGRES_PASSWORD: ${CODEBATTLE_DB_PASSWORD}
42+
command: postgres -c 'max_connections=1000'
4243
volumes:
4344
- pg_data:/var/lib/postgresql/data
4445

services/app/apps/codebattle/lib/codebattle/pub_sub/events.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ defmodule Codebattle.PubSub.Events do
262262
event: "game:finished",
263263
payload: %{
264264
game_id: game.id,
265+
tournament_id: game.tournament_id,
265266
game_state: game.state,
266267
game: %{
267268
id: Game.Helpers.get_game_id(game),

services/app/apps/codebattle/lib/codebattle/users_rank_update_server.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ defmodule Codebattle.UsersRankUpdateServer do
2020
def init(_) do
2121
Process.send_after(self(), :work, @timeout)
2222

23-
Codebattle.PubSub.subscribe("main")
2423
Codebattle.PubSub.subscribe("games")
2524
Logger.debug("Start UsersRankServer")
2625
{:ok, true}
@@ -37,7 +36,7 @@ defmodule Codebattle.UsersRankUpdateServer do
3736
{:noreply, state}
3837
end
3938

40-
def handle_info(%{event: "game:finished"}, state) do
39+
def handle_info(%{event: "game:finished", payload: %{tournament_id: nil}}, state) do
4140
do_work()
4241
{:noreply, state}
4342
end

services/app/apps/codebattle/lib/codebattle_web/channels/tournament_channel.ex

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,18 @@ defmodule CodebattleWeb.TournamentChannel do
189189

190190
push(socket, "tournament:update", %{
191191
tournament:
192-
Map.drop(payload.tournament, [:players, :matches, :players_table, :matches_table]),
193-
players: Helpers.get_players(payload.tournament),
192+
Map.drop(payload.tournament, [
193+
:__struct__,
194+
:__meta__,
195+
:creator,
196+
:players,
197+
:matches,
198+
:players_table,
199+
:matches_table,
200+
:round_tasks,
201+
:played_pair_ids
202+
]),
203+
players: Helpers.get_top_players(payload.tournament),
194204
matches: matches
195205
})
196206

@@ -250,7 +260,7 @@ defmodule CodebattleWeb.TournamentChannel do
250260

251261
Codebattle.PubSub.subscribe("tournament:#{tournament.id}:player:#{current_user.id}")
252262

253-
if Codebattle.User.admin?(current_user) do
263+
if Helpers.can_moderate?(tournament, current_user) do
254264
Codebattle.PubSub.subscribe("tournament:#{tournament.id}")
255265
else
256266
Codebattle.PubSub.subscribe("tournament:#{tournament.id}:common")
@@ -262,15 +272,16 @@ defmodule CodebattleWeb.TournamentChannel do
262272
defp get_tournament_join_payload(%{type: type} = tournament, socket)
263273
when type in ["swiss", "ladder", "stairway"] do
264274
current_user = socket.assigns.current_user
265-
matches = Helpers.get_matches_by_players(tournament, [current_user.id])
266275

267-
players =
268-
if Codebattle.User.admin?(current_user) do
269-
[Helpers.get_player(tournament, current_user.id)] ++
270-
Helpers.get_paginated_players(tournament, 0, 30)
276+
{matches, players} =
277+
if Helpers.can_moderate?(tournament, current_user) do
278+
{Helpers.get_matches(tournament),
279+
[Helpers.get_player(tournament, current_user.id)] ++
280+
Helpers.get_paginated_players(tournament, 0, 30)}
271281
else
272-
[Helpers.get_player(tournament, current_user.id)] ++
273-
Helpers.get_top_players(tournament)
282+
{Helpers.get_matches_by_players(tournament, [current_user.id]),
283+
[Helpers.get_player(tournament, current_user.id)] ++
284+
Helpers.get_top_players(tournament)}
274285
end
275286

276287
%{

services/app/apps/codebattle/mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ defmodule Codebattle.MixProject do
7171
{:exfake, "~> 1.0.0"},
7272
{:fun_with_flags, "~> 1.10.1"},
7373
{:fun_with_flags_ui, "~> 0.8"},
74+
{:recon, "~> 2.5"},
7475

7576
# dev_and_test
7677
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},

services/app/config/config.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ config :codebattle, ecto_repos: [Codebattle.Repo]
99

1010
# Configures the endpoint
1111
config :codebattle, CodebattleWeb.Endpoint,
12+
http: [
13+
port: System.get_env("CODEBATTLE_PORT", "4000"),
14+
transport_options: [
15+
max_connections: 30000,
16+
num_acceptors: 500
17+
]
18+
],
1219
url: [host: "localhost"],
1320
secret_key_base: "zQ3/vT3oIVM94qXO7IgWeAqbLSAyGA9em6fdBw7OdbDnbeotEkWYANrjJWYNWpd/",
1421
render_errors: [view: CodebattleWeb.ErrorView, accepts: ~w(html json), layout: false],

services/app/config/prod.exs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import Config
22

33
config :codebattle, CodebattleWeb.Endpoint,
4-
http: [port: System.get_env("CODEBATTLE_PORT", "4000")],
5-
url: [scheme: "https", host: "codebattle.hexlet.io", port: 443],
4+
http: [
5+
port: System.get_env("CODEBATTLE_PORT", "4000"),
6+
transport_options: [
7+
max_connections: 30000,
8+
num_acceptors: 500
9+
]
10+
],
11+
url: [
12+
scheme: "https",
13+
host: System.get_env("CODEBATTLE_HOST", "codebattle.hexlet.io"),
14+
port: 443
15+
],
616
cache_static_manifest: "priv/static/cache_manifest.json",
717
server: true,
818
root: ".",

services/app/mix.lock

Lines changed: 11 additions & 10 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)