@@ -27,12 +27,10 @@ defmodule Codebattle.Tournament.Storage.Ranking do
2727 end
2828
2929 def put_single_record ( tournament , place , record ) do
30- try do
31- :ets . insert ( tournament . ranking_table , { place , record . id , record } )
32- rescue
33- _e ->
34- IO . inspect ( { place , record . id , record } , label: "Error inserting single ranking record" )
35- end
30+ :ets . insert ( tournament . ranking_table , { place , record . id , record } )
31+ rescue
32+ _e ->
33+ IO . inspect ( { place , record . id , record } , label: "Error inserting single ranking record" )
3634 end
3735
3836 def drop_player ( tournament , player_id ) do
@@ -47,59 +45,49 @@ defmodule Codebattle.Tournament.Storage.Ranking do
4745 end
4846
4947 def get_first ( tournament , limit ) do
50- try do
51- :ets . select ( tournament . ranking_table , [
52- { { :"$1" , :_ , :"$3" } , [ { :>= , :"$1" , 1 } , { :"=<" , :"$1" , limit } ] , [ :"$3" ] }
53- ] )
54- rescue
55- _e ->
56- IO . inspect ( { tournament , limit } , label: "Error getting first ranking records" )
57- [ ]
58- end
48+ :ets . select ( tournament . ranking_table , [
49+ { { :"$1" , :_ , :"$3" } , [ { :>= , :"$1" , 1 } , { :"=<" , :"$1" , limit } ] , [ :"$3" ] }
50+ ] )
51+ rescue
52+ _e ->
53+ IO . inspect ( { tournament , limit } , label: "Error getting first ranking records" )
54+ [ ]
5955 end
6056
6157 def get_all ( tournament ) do
62- try do
63- :ets . select ( tournament . ranking_table , [ { { :_ , :_ , :"$3" } , [ ] , [ :"$3" ] } ] )
64- rescue
65- _e ->
66- IO . inspect ( tournament , label: "Error getting all ranking records" )
67- [ ]
68- end
58+ :ets . select ( tournament . ranking_table , [ { { :_ , :_ , :"$3" } , [ ] , [ :"$3" ] } ] )
59+ rescue
60+ _e ->
61+ IO . inspect ( tournament , label: "Error getting all ranking records" )
62+ [ ]
6963 end
7064
7165 def get_by_id ( tournament , id ) do
72- try do
73- case :ets . select ( tournament . ranking_table , [ { { :_ , :"$2" , :"$3" } , [ { :== , :"$2" , id } ] , [ :"$3" ] } ] ) do
74- [ ranking_entity ] -> ranking_entity
75- [ ] -> nil
76- end
77- rescue
78- _e ->
79- IO . inspect ( { tournament , id } , label: "Error getting ranking record by id" )
80- nil
66+ case :ets . select ( tournament . ranking_table , [ { { :_ , :"$2" , :"$3" } , [ { :== , :"$2" , id } ] , [ :"$3" ] } ] ) do
67+ [ ranking_entity ] -> ranking_entity
68+ [ ] -> nil
8169 end
70+ rescue
71+ _e ->
72+ IO . inspect ( { tournament , id } , label: "Error getting ranking record by id" )
73+ nil
8274 end
8375
8476 def count ( tournament ) do
85- try do
86- :ets . select_count ( tournament . ranking_table , [ { :_ , [ ] , [ true ] } ] )
87- rescue
88- _e ->
89- IO . inspect ( tournament , label: "Error counting ranking records" )
90- 0
91- end
77+ :ets . select_count ( tournament . ranking_table , [ { :_ , [ ] , [ true ] } ] )
78+ rescue
79+ _e ->
80+ IO . inspect ( tournament , label: "Error counting ranking records" )
81+ 0
9282 end
9383
9484 def get_slice ( tournament , start_place , end_place ) do
95- try do
96- :ets . select ( tournament . ranking_table , [
97- { { :"$1" , :_ , :"$3" } , [ { :>= , :"$1" , start_place } , { :"=<" , :"$1" , end_place } ] , [ :"$3" ] }
98- ] )
99- rescue
100- _e ->
101- IO . inspect ( { tournament , start_place , end_place } , label: "Error getting slice of ranking records" )
102- [ ]
103- end
85+ :ets . select ( tournament . ranking_table , [
86+ { { :"$1" , :_ , :"$3" } , [ { :>= , :"$1" , start_place } , { :"=<" , :"$1" , end_place } ] , [ :"$3" ] }
87+ ] )
88+ rescue
89+ _e ->
90+ IO . inspect ( { tournament , start_place , end_place } , label: "Error getting slice of ranking records" )
91+ [ ]
10492 end
10593end
0 commit comments