-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to update project groups agg data
- Loading branch information
Showing
2 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
django/apps/aggregated/management/commands/update_project_groups_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import time | ||
|
||
from apps.existing_database.models import Project | ||
from django.core.management.base import BaseCommand | ||
from django.db import connection, transaction | ||
|
||
from .update_aggregated_data import UPDATE_PROJECT_GROUP_DATA_USING_PROJECT_ID | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, **_): | ||
project_qs = Project.objects.all() | ||
total_projects = project_qs.count() | ||
self.stdout.write(f"Total projects: {total_projects}") | ||
for index, project_id in enumerate( | ||
project_qs.values_list("project_id", flat=True), | ||
start=1, | ||
): | ||
self.stdout.write( | ||
"Running calculation for project ID " | ||
f"({index}/{total_projects}): {project_id}" | ||
) | ||
with transaction.atomic(): | ||
start_time = time.time() | ||
with connection.cursor() as cursor: | ||
cursor.execute( | ||
UPDATE_PROJECT_GROUP_DATA_USING_PROJECT_ID, | ||
dict(project_id=project_id), | ||
) | ||
self.stdout.write( | ||
self.style.SUCCESS( | ||
f"- Successfull. Runtime: {time.time() - start_time} seconds" | ||
) | ||
) |