Skip to content

Commit

Permalink
Ensure clean_locations iterates all Locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Cochrane (Lead developer, DataMade) committed Oct 15, 2019
1 parent 92e6d31 commit 7de3921
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sfm_pc/management/commands/clean_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ def handle(self, *args, **options):
).delete()
else:
num_deleted = 0
paginator = Paginator(Location.objects.all().order_by('id'), 50)
batch_size = 100
page_range = (location_count//batch_size)+1
with tqdm(total=location_count) as progress_bar:
for page in paginator.page_range:
for location in paginator.page(page).object_list:
for page in range(page_range):
for location in Location.objects.all()[:batch_size]:
if not location.related_entities:
location.delete()
num_deleted += 1
Expand Down

0 comments on commit 7de3921

Please sign in to comment.