Skip to content

Commit

Permalink
Replace nested if conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Aug 1, 2024
1 parent 421b9f1 commit ea74e66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 6 additions & 10 deletions browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ def transform(row):
offset=max(0, offset - qcoll.total_rows()), limit=limit - len(colls), output=AS_DICT)
datas = map(transform, list(qdata))

if len(colls) + len(datas) == 0:
# No results at all?
# Make sure the collection actually exists.
if not collection.exists(ctx, coll):
return api.Error('nonexistent', 'The given path does not exist')
# No results at all? Make sure the collection actually exists.
if len(colls) + len(datas) == 0 and not collection.exists(ctx, coll):
return api.Error('nonexistent', 'The given path does not exist')
# (checking this beforehand would waste a query in the most common situation)

return OrderedDict([('total', qcoll.total_rows() + qdata.total_rows()),
Expand Down Expand Up @@ -177,11 +175,9 @@ def transform(row):

colls = map(transform, [d for d in list(qcoll) if _filter_vault_deposit_index(d)])

if len(colls) == 0:
# No results at all?
# Make sure the collection actually exists.
if not collection.exists(ctx, coll):
return api.Error('nonexistent', 'The given path does not exist')
# No results at all? Make sure the collection actually exists.
if len(colls) == 0 and not collection.exists(ctx, coll):
return api.Error('nonexistent', 'The given path does not exist')
# (checking this beforehand would waste a query in the most common situation)

return OrderedDict([('total', qcoll.total_rows()),
Expand Down
8 changes: 3 additions & 5 deletions datarequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,11 +846,9 @@ def transform_status(row):
datarequest['status'] = datarequest_status['status']
break

if len(colls) == 0:
# No results at all?
# Make sure the collection actually exists
if not collection.exists(ctx, coll):
return api.Error('nonexistent', 'The given path does not exist')
# No results at all? Make sure the collection actually exists.
if len(colls) == 0 and not collection.exists(ctx, coll):
return api.Error('nonexistent', 'The given path does not exist')
# (checking this beforehand would waste a query in the most common situation)

return OrderedDict([('total', qcoll.total_rows()), ('items', colls)])
Expand Down

0 comments on commit ea74e66

Please sign in to comment.