Skip to content

Sync versions: don't fetch/return all versions #8114

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
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 10 additions & 10 deletions readthedocs/api/v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def sync_versions_to_db(project, versions, type): # pylint: disable=redefined-b
latest_version.verbose_name = LATEST_VERBOSE_NAME
latest_version.save()
if added:
log.info('(Sync Versions) Added Versions: [%s] ', ' '.join(added))
log.info(
'(Sync Versions) Added Versions: versions_count=%d versions=[%s] ',
len(added), ' '.join(added[:100]),
)
return added


Expand Down Expand Up @@ -208,15 +211,12 @@ def delete_versions_from_db(project, tags_data, branches_data):
)
.exclude(active=True)
)
deleted_versions = set(to_delete_qs.values_list('slug', flat=True))
if deleted_versions:
log.info(
'(Sync Versions) Deleted Versions: project=%s, versions=[%s]',
project.slug, ' '.join(deleted_versions),
)
to_delete_qs.delete()

return deleted_versions
_, deleted = to_delete_qs.delete()
versions_count = deleted.get('builds.Version')
log.info(
'(Sync Versions) Deleted Versions: project=%s versions_count=[%d]',
project.slug, versions_count,
)


def get_deleted_active_versions(project, tags_data, branches_data):
Expand Down
6 changes: 2 additions & 4 deletions readthedocs/builds/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
)
from readthedocs.builds.constants import (
BRANCH,
EXTERNAL,
BUILD_STATUS_FAILURE,
BUILD_STATUS_PENDING,
BUILD_STATUS_SUCCESS,
EXTERNAL,
MAX_BUILD_COMMAND_SIZE,
TAG,
)
Expand Down Expand Up @@ -284,7 +284,7 @@ def sync_versions_task(project_pk, tags_data, branches_data, **kwargs):
)
added_versions.update(result)

deleted_versions = delete_versions_from_db(
delete_versions_from_db(
project=project,
tags_data=tags_data,
branches_data=branches_data,
Expand Down Expand Up @@ -333,5 +333,3 @@ def sync_versions_task(project_pk, tags_data, branches_data, **kwargs):
promoted_version.active = True
promoted_version.save()
trigger_build(project=project, version=promoted_version)

return list(added_versions), list(deleted_versions)
13 changes: 10 additions & 3 deletions readthedocs/rtd_tests/tests/test_sync_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def setUp(self):
type=TAG,
)
self.pip.update_stable_version()
self.pip.save()

def test_proper_url_no_slash(self):
branches_data = [
Expand All @@ -69,13 +70,19 @@ def test_proper_url_no_slash(self):
},
]

added_versions, deleted_versions = sync_versions_task(
self.assertEqual(
set(self.pip.versions.all().values_list('slug', flat=True)),
{'master', 'latest', 'stable', '0.8.1', '0.8', 'to_delete'},
)
sync_versions_task(
self.pip.pk,
branches_data=branches_data,
tags_data=[],
)
self.assertEqual(deleted_versions, ['to_delete'])
self.assertEqual(added_versions, ['to_add'])
self.assertEqual(
set(self.pip.versions.all().values_list('slug', flat=True)),
{'master', 'latest', 'stable', '0.8.1', '0.8', 'to_add'},
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other tests were already checking the versions from the db instead of the return value :)


def test_new_tag_update_active(self):
Version.objects.create(
Expand Down