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

Batch API progress data #1506

Open
bwbroersma opened this issue Sep 17, 2024 · 1 comment
Open

Batch API progress data #1506

bwbroersma opened this issue Sep 17, 2024 · 1 comment
Assignees
Labels
documentation documentation

Comments

@bwbroersma
Copy link
Collaborator

There is an undocumented progress query parameter in the List requests and Request status:

provide_progress = request.GET.get("progress")
provide_progress = provide_progress and provide_progress.lower() == "true"
batch_requests = BatchRequest.objects.filter(user=user).order_by("-id")[:limit]
batch_info = []
for batch_request in batch_requests:
request_dict = batch_request.to_api_dict()
if provide_progress:
total_domains = BatchDomain.objects.filter(batch_request=batch_request).count()
finished_domains = BatchDomain.objects.filter(
batch_request=batch_request, status__in=(BatchDomainStatus.done, BatchDomainStatus.error)
).count()
request_dict["progress"] = f"{finished_domains}/{total_domains}"
request_dict["num_domains"] = total_domains
batch_info.append(request_dict)

def get_request(request, batch_request, user):
provide_progress = request.GET.get("progress")
provide_progress = provide_progress and provide_progress.lower() == "true"
res = {"request": batch_request.to_api_dict()}
if provide_progress:
total_domains = BatchDomain.objects.filter(batch_request=batch_request).count()
finished_domains = BatchDomain.objects.filter(
batch_request=batch_request, status__in=(BatchDomainStatus.done, BatchDomainStatus.error)
).count()
res["request"]["progress"] = f"{finished_domains}/{total_domains}"
res["request"]["num_domains"] = total_domains

Does the ORM of this result in two (heavy) SQL SELECT COUNT(*) queries? (heavy because count-* must check the visibility of each row)

Should this option be documented or enabled by default for non-finished domains? (and maybe the domain count can be added to the metadata?)

@bwbroersma bwbroersma added documentation documentation discuss Requires further team discussion and decisions labels Sep 17, 2024
@bwbroersma bwbroersma self-assigned this Sep 17, 2024
@bwbroersma
Copy link
Collaborator Author

Assigned to self, steps:

  • Run batch in develop
  • Check PostgreSQL queries (by enable logging)
  • Fill relevant database tables with dummy data
  • Explain queries to estimate impact

@bwbroersma bwbroersma removed the discuss Requires further team discussion and decisions label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation documentation
Development

No branches or pull requests

1 participant