Skip to content

Commit

Permalink
Make it more clear what is happening when no changes are done by sort…
Browse files Browse the repository at this point in the history
…-content
  • Loading branch information
Dan Davis committed Nov 23, 2022
1 parent 2b90aac commit 952a497
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions snowboard/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,19 @@ def normalize_string_for_sorting(name: str):
changed = sorted_content[sorted_content.order != sorted_content.new_order]
total_count = len(changed)

progress = Bar("Updating ", max=total_count)
stime = time.perf_counter()
for index, row in changed.iterrows():
# "index" is a pandas "Label" and must be converted to string
sys_id = str(index)
r = content_api.update_record(sys_id, {"order": row.new_order})
r.raise_for_status()
progress.next()

progress.finish()
elapsed = time.perf_counter() - stime
print("Updated {} records in {:.2f} seconds".format(total_count, elapsed))
if total_count == 0:
print("Nothing to do - topic is already in sorted order")
else:
progress = Bar("Updating ", max=total_count)
stime = time.perf_counter()
for index, row in changed.iterrows():
# "index" is a pandas "Label" and must be converted to string
sys_id = str(index)
r = content_api.update_record(sys_id, {"order": row.new_order})
r.raise_for_status()
progress.next()

progress.finish()
elapsed = time.perf_counter() - stime
print("Updated {} records in {:.2f} seconds".format(total_count, elapsed))
return 0

0 comments on commit 952a497

Please sign in to comment.