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

Remove old import task msg on import, and managment command #1368 #1378

Merged
merged 2 commits into from
Nov 27, 2018
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
28 changes: 28 additions & 0 deletions galaxy/main/management/commands/import_task_message_cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.core.management.base import BaseCommand

from galaxy.main.models import Repository, ImportTaskMessage


class Command(BaseCommand):
help = ('For each repo, deletes all import_task_messages '
'except for messages in latest import_task.')

def handle(self, *args, **kwargs):
total_msg_to_delete = 0
total_delete_calls = 0

repos = Repository.objects.all()
for repo in repos:
tasks_non_latest = repo.import_tasks.order_by('-id')[1:]

messages_non_latest = ImportTaskMessage.objects.filter(
task__in=tasks_non_latest
)

total_msg_to_delete += messages_non_latest.count()
total_delete_calls += 1

messages_non_latest.delete()

print('total_msg_to_delete', total_msg_to_delete)
print('total_delete_calls', total_delete_calls)
18 changes: 18 additions & 0 deletions galaxy/worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def _import_repository(import_task, logger):

_update_task_msg_content_id(import_task)
_update_quality_score(import_task)
_cleanup_old_task_msg(import_task)

# Updating versions has to go last because:
# - we don't want to update the version number if the import fails.
Expand Down Expand Up @@ -349,6 +350,23 @@ def _update_quality_score(import_task):
LOG.debug(u'repo quality score: {}'.format(repository.quality_score))


def _cleanup_old_task_msg(import_task):
old_task_ids = models.ImportTask.objects.filter(
repository=import_task.repository,
).exclude(
id=import_task.id,
).values_list(
'id',
flat=True,
)

if old_task_ids:
old_task_msgs = models.ImportTaskMessage.objects.filter(
task__in=old_task_ids
)
old_task_msgs.delete()


def _update_namespace(repository):
# Use GitHub repo to update namespace attributes
if repository.owner.type == 'Organization':
Expand Down