Skip to content

Commit

Permalink
add foreign key to AnsibleRepository
Browse files Browse the repository at this point in the history
fixes: pulp#1506
  • Loading branch information
jerabekjiri committed Jul 7, 2023
1 parent 219847c commit c41c66d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/1506.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switched to foreign key for ``last_sync_task`` in AnsibleRepository model due to performance issues.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.3 on 2023-07-07 11:57

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("core", "0107_distribution_hidden"),
("ansible", "0055_ansiblerepository_last_sync_task"),
]

operations = [
migrations.AlterField(
model_name="ansiblerepository",
name="last_sync_task",
field=models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="core.task"
),
),
]
9 changes: 5 additions & 4 deletions pulp_ansible/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ class AnsibleRepository(Repository, AutoAddObjPermsMixin):
last_synced_metadata_time = models.DateTimeField(null=True)
gpgkey = models.TextField(null=True)
private = models.BooleanField(default=False)

@property
def last_sync_task(self):
return _get_last_sync_task(self.pk)
last_sync_task = models.ForeignKey(
Task,
on_delete=models.CASCADE,
null=True,
)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
Expand Down
3 changes: 3 additions & 0 deletions pulp_ansible/app/tasks/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def sync(remote_pk, repository_pk, mirror, optimize):
remote = CollectionRemote.objects.get(pk=remote_pk)
repository = AnsibleRepository.objects.get(pk=repository_pk)

repository.last_sync_task = Task.current()
repository.save(update_fields=["last_sync_task"])

is_repo_remote = False
if repository.remote:
is_repo_remote = remote.pk == repository.remote.pk
Expand Down

0 comments on commit c41c66d

Please sign in to comment.