Skip to content

Commit bcf9f19

Browse files
committed
CP-49045: optimize database uuid lookup: use index
An index (map) has already been created, but it was only used to lookup Refs, not UUIDs. A latent bug in the UUID index was fixed in a previous commit. Signed-off-by: Edwin Török <edwin.torok@citrix.com>
1 parent c636b62 commit bcf9f19

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

ocaml/database/db_cache_impl.ml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,13 @@ let read_field_where' conv t rcd =
277277
let read_field_where t rcd = read_field_where' Fun.id t rcd
278278

279279
let db_get_by_uuid t tbl uuid_val =
280-
match
281-
read_field_where' Schema.CachedValue.string_of t
282-
{
283-
table= tbl
284-
; return= Db_names.ref
285-
; where_field= Db_names.uuid
286-
; where_value= uuid_val
287-
}
288-
with
289-
| [] ->
290-
raise (Read_missing_uuid (tbl, "", uuid_val))
291-
| [r] ->
280+
let db = get_database t in
281+
match Database.lookup_uuid uuid_val db with
282+
| Some (tbl', r) when String.equal tbl tbl' ->
292283
r
293284
| _ ->
294-
raise (Too_many_values (tbl, "", uuid_val))
285+
(* we didn't find the UUID, or it belonged to another table *)
286+
raise (Read_missing_uuid (tbl, "", uuid_val))
295287

296288
let db_get_by_uuid_opt t tbl uuid_val =
297289
match

ocaml/database/db_cache_types.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ module Database = struct
508508

509509
let lookup_key key db = KeyMap.find_opt (Ref key) db.keymap
510510

511+
let lookup_uuid key db = KeyMap.find_opt (Uuid key) db.keymap
512+
511513
let make schema =
512514
{
513515
tables= TableSet.empty

ocaml/database/db_cache_types.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ module Database : sig
195195

196196
val lookup_key : string -> t -> (string * string) option
197197

198+
val lookup_uuid : string -> t -> (string * string) option
199+
198200
val reindex : t -> t
199201

200202
val register_callback : string -> (update -> t -> unit) -> t -> t

0 commit comments

Comments
 (0)