Skip to content

Commit

Permalink
Updated data migrations to only migrate RemoteRepositories of recentl…
Browse files Browse the repository at this point in the history
…y loggedin users
  • Loading branch information
saadmk11 committed Nov 14, 2020
1 parent 0ce8cff commit 863d329
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
Expand Up @@ -5,7 +5,7 @@
import logging

from django.db import migrations

from django.utils import timezone

log = logging.getLogger(__name__)

Expand All @@ -31,7 +31,9 @@ def remote_relations_generator(relations, batch_size):

yield relation

relations_queryset = RemoteRelation.objects.all().select_related(
relations_queryset = RemoteRelation.objects.filter(
user__last_login__gte=timezone.now() - timezone.timedelta(days=30)
).select_related(
'remoterepository'
).only(
'account_id', 'active', 'admin', 'created',
Expand All @@ -41,7 +43,7 @@ def remote_relations_generator(relations, batch_size):
'remoterepository__modified_date'
)

batch_size = 5000
batch_size = 1000
remote_relations = remote_relations_generator(
relations_queryset, batch_size
)
Expand Down

This file was deleted.

5 changes: 5 additions & 0 deletions readthedocs/oauth/models.py
Expand Up @@ -103,6 +103,8 @@ class RemoteRepository(models.Model):
blank=True,
on_delete=models.CASCADE,
)
active = models.BooleanField(_('Active'), default=False)

project = models.OneToOneField(
Project,
on_delete=models.SET_NULL,
Expand Down Expand Up @@ -145,13 +147,16 @@ class RemoteRepository(models.Model):
html_url = models.URLField(_('HTML URL'), null=True, blank=True)

private = models.BooleanField(_('Private repository'), default=False)
admin = models.BooleanField(_('Has admin privilege'), default=False)
vcs = models.CharField(
_('vcs'),
max_length=200,
blank=True,
choices=REPO_CHOICES,
)

json = models.TextField(_('Serialized API response'))

objects = RemoteRepositoryQuerySet.as_manager()

class Meta:
Expand Down

0 comments on commit 863d329

Please sign in to comment.