Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set chunk_size for queryset.iterator #1277

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/deployments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def disable_old_timeseries(self, request, queryset):
platform_id__in=platforms_ids,
)

for ts in ts_week_ago.iterator():
for ts in ts_week_ago.iterator(chunk_size=100):
ts.active = False
timeseries_to_update.append(ts)

Expand All @@ -354,7 +354,7 @@ def disable_old_timeseries(self, request, queryset):
def refresh_timeseries(self, request, queryset):
datasets_to_queue = set()

for platform in queryset.iterator():
for platform in queryset.iterator(chunk_size=100):
for ts in platform.timeseries_set.all():
datasets_to_queue.add(ts.dataset_id)

Expand All @@ -377,7 +377,7 @@ def remove_end_time(self, request, queryset):

year_ago = timezone.now() - year

for platform in queryset.iterator():
for platform in queryset.iterator(chunk_size=100):
platforms.append(platform)
for ts in platform.timeseries_set.filter(end_time__gte=year_ago):
ts.end_time = None
Expand All @@ -398,7 +398,7 @@ def disable_timeseries(self, request, queryset):
platforms = []
timeseries = []

for platform in queryset.iterator():
for platform in queryset.iterator(chunk_size=100):
platforms.append(platform)
for ts in platform.timeseries_set.all():
ts.active = False
Expand All @@ -416,7 +416,7 @@ def enable_timeseries(self, request, queryset):
platforms = []
timeseries = []

for platform in queryset.iterator():
for platform in queryset.iterator(chunk_size=100):
platforms.append(platform)
for ts in platform.timeseries_set.all():
ts.active = True
Expand All @@ -440,7 +440,7 @@ class ErddapServerAdmin(admin.ModelAdmin):
def refresh_server(self, request, queryset):
queued_servers = []

for server in queryset.iterator():
for server in queryset.iterator(chunk_size=100):
refresh.refresh_server.delay(server.id, healthcheck=False)
queued_servers.append(server)

Expand All @@ -454,7 +454,7 @@ def disable_timeseries(self, request, queryset):
datasets = []
timeseries = []

for server in queryset.iterator():
for server in queryset.iterator(chunk_size=100):
for dataset in server.erddapdataset_set.all():
datasets.append(dataset)
for ts in dataset.timeseries_set.all():
Expand All @@ -473,7 +473,7 @@ def enable_timeseries(self, request, queryset):
datasets = []
timeseries = []

for server in queryset.iterator():
for server in queryset.iterator(chunk_size=100):
for dataset in server.erddapdataset_set.all():
datasets.append(dataset)
for ts in dataset.timeseries_set.all():
Expand Down Expand Up @@ -580,7 +580,7 @@ def refresh_status(self, obj: ErddapDataset):
def refresh_dataset(self, request, queryset):
queued_datasets = []

for dataset in queryset.iterator():
for dataset in queryset.iterator(chunk_size=100):
refresh.refresh_dataset.delay(dataset.id, healthcheck=False)
queued_datasets.append(dataset)

Expand All @@ -594,7 +594,7 @@ def disable_timeseries(self, request, queryset):
datasets = []
timeseries = []

for dataset in queryset.iterator():
for dataset in queryset.iterator(chunk_size=100):
datasets.append(dataset)
for ts in dataset.timeseries_set.all():
ts.active = False
Expand All @@ -612,7 +612,7 @@ def enable_timeseries(self, request, queryset):
datasets = []
timeseries = []

for dataset in queryset.iterator():
for dataset in queryset.iterator(chunk_size=100):
datasets.append(dataset)
for ts in dataset.timeseries_set.all():
ts.active = True
Expand Down
2 changes: 1 addition & 1 deletion app/deployments/tasks/old_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def more_thank_a_week_old():

platforms = {}

for ts in ts_week_ago.iterator():
for ts in ts_week_ago.iterator(chunk_size=100):
platform = platforms.get(ts.platform.name, [])

platform.append(f"{ts} @ {ts.value_time.strftime('%Y-%m-%d %H:%M')}")
Expand Down
Loading