Skip to content

Commit

Permalink
fix(unique_ids): Fix performance regression in 56a5dbf in case where …
Browse files Browse the repository at this point in the history
…there are missing/invalid IDs and non-unique items
  • Loading branch information
jpmckinney committed Feb 28, 2024
1 parent 84006e6 commit 9ad32b8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions libcove/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def unique_ids(validator, ui, instance, schema, id_names=["id"]):
if ui and validator.is_type(instance, "array"):
non_unique_ids = set()
all_ids = set()
run_uniq = False
uniq_has_run = False

for item in instance:
try:
Expand All @@ -104,15 +104,14 @@ def unique_ids(validator, ui, instance, schema, id_names=["id"]):
if item_ids in all_ids:
non_unique_ids.add(item_ids)
all_ids.add(item_ids)
else:
run_uniq = True

if run_uniq and not uniq(instance):
msg = "Array has non-unique elements"
err = ValidationError(msg, instance=instance)
err.error_id = "uniqueItems_no_ids"
yield err
return
elif not uniq_has_run:
if not uniq(instance):
msg = "Array has non-unique elements"
err = ValidationError(msg, instance=instance)
err.error_id = "uniqueItems_no_ids"
yield err
return
uniq_has_run = True

for non_unique_id in sorted(non_unique_ids):
if len(id_names) == 1:
Expand Down

0 comments on commit 9ad32b8

Please sign in to comment.