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

Fix: avoid loading unnnecesary data into memory #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 5 additions & 6 deletions import_export_celery/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ def run_export_job_action(modeladmin, request, queryset):


def create_export_job_action(modeladmin, request, queryset):
if queryset:
arbitrary_obj = queryset.first()
if queryset is not None:
ej = ExportJob.objects.create(
app_label=arbitrary_obj._meta.app_label,
model=arbitrary_obj._meta.model_name,
app_label=queryset.model._meta._meta.app_label,
model=queryset.model._meta._meta.model_name,
queryset=json.dumps(
[
str(obj.pk) if isinstance(obj.pk, UUID) else obj.pk
for obj in queryset
str(pk) if isinstance(pk, UUID) else pk
for pk in queryset.values_list("pk", flat=True)
]
),
site_of_origin=request.scheme + "://" + request.get_host(),
Expand Down
3 changes: 2 additions & 1 deletion import_export_celery/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Author: Timothy Hobbs <timothy <at> hobbs.cz>
from django.utils import timezone
from django.db.models import QuerySet
import os

from celery import shared_task
Expand Down Expand Up @@ -215,7 +216,7 @@ def run_export_job(pk):
export_job = models.ExportJob.objects.get(pk=pk)
resource_class = export_job.get_resource_class()
queryset = export_job.get_queryset()
qs_len = len(queryset)
qs_len = queryset.count() if isinstance(queryset, QuerySet) else len(queryset)

class Resource(resource_class):
def __init__(self, export_job, *args, **kwargs):
Expand Down