Skip to content

Commit ae60d68

Browse files
committed
CP-54828: avoid raising exceptions all the time in the RBAC code
We can use Hashtbl.mem instead of catching the exception from Hashtbl.find. Signed-off-by: Edwin Török <edwin.torok@cloud.com>
1 parent 7bcc5fc commit ae60d68

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

ocaml/xapi/xapi_local_session.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ let create ~__context ~pool =
3131
with_lock m (fun () -> Hashtbl.replace table r session) ;
3232
r
3333

34-
let get_record ~__context ~self = with_lock m (fun () -> Hashtbl.find table self)
34+
let has_record ~__context ~self = with_lock m (fun () -> Hashtbl.mem table self)
3535

3636
let destroy ~__context ~self = with_lock m (fun () -> Hashtbl.remove table self)
3737

3838
let local_session_hook ~__context ~session_id =
39-
try
40-
ignore (get_record ~__context ~self:session_id) ;
41-
true
42-
with _ -> false
39+
has_record ~__context ~self:session_id

ocaml/xapi/xapi_local_session.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ val get_all : __context:Context.t -> API.ref_session list
1919

2020
val create : __context:Context.t -> pool:bool -> API.ref_session
2121

22-
val get_record : __context:Context.t -> self:API.ref_session -> t
23-
2422
val destroy : __context:Context.t -> self:API.ref_session -> unit
2523

2624
val local_session_hook :

quality-gate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ unixgetenv () {
110110
}
111111

112112
hashtblfind () {
113-
N=35
113+
N=34
114114
# Looks for all .ml files except the ones using Core.Hashtbl.find,
115115
# which already returns Option
116116
HASHTBLFIND=$(git grep -P -r --count 'Hashtbl.find(?!_opt)' -- '**/*.ml' ':!ocaml/xapi-storage-script/main.ml' | cut -d ':' -f 2 | paste -sd+ - | bc)

0 commit comments

Comments
 (0)