Skip to content

Deprecation: improve Celery task db query #10414

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

Merged
merged 5 commits into from
Jun 12, 2023
Merged
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
14 changes: 8 additions & 6 deletions readthedocs/projects/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def deprecated_config_file_used_notification():
queryset = User.objects.filter(username__in=users, profile__banned=False).order_by(
"id"
)

n_users = queryset.count()
for i, user in enumerate(queryset.iterator()):
if i % 500 == 0:
Expand All @@ -283,14 +284,15 @@ def deprecated_config_file_used_notification():
)

# All the projects for this user that don't have a configuration file
user_projects = (
AdminPermission.projects(user, admin=True)
.filter(slug__in=projects)
.only("slug")
# Use set() intersection in Python that's pretty quick since we only need the slugs.
# Otherwise we have to pass 82k slugs to the DB query, which makes it pretty slow.
user_projects = AdminPermission.projects(user, admin=True).values_list(
"slug", flat=True
)
user_projects = list(set(user_projects) & projects)

user_project_slugs = ", ".join([p.slug for p in user_projects[:5]])
if user_projects.count() > 5:
user_project_slugs = ", ".join(user_projects[:5])
if len(user_projects) > 5:
user_project_slugs += " and others..."

n_site = DeprecatedConfigFileSiteNotification(
Expand Down