Skip to content

Commit

Permalink
WIP: Improve optimize sync conditions
Browse files Browse the repository at this point in the history
This PR achieves the following:

- Do not disable optimize if we are switching from mirror to not mirror
  between two syncs. We can optmize in this case.
- Log additional reasons why we did not optimize in certain cases.
- Improve the readability of optimize conditions.
  • Loading branch information
quba42 committed Sep 26, 2023
1 parent 1adc989 commit 73a26ab
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pulp_deb/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,21 @@ def __init__(self, remote, optimize, mirror, previous_repo_version, *args, **kwa
self.remote = remote
self.optimize = optimize
self.previous_repo_version = previous_repo_version
self.previous_sync_info = defaultdict(dict, previous_repo_version.info)
self.sync_info = defaultdict()
self.sync_info["remote_options"] = self._gen_remote_options()
self.sync_info["sync_options"] = {
"optimize": optimize,
"mirror": mirror,
}
self.parsed_url = urlparse(remote.url)
self.sync_options_unchanged = (
self.previous_sync_info["remote_options"] == self.sync_info["remote_options"]
and self.previous_sync_info["sync_options"]["mirror"]
== self.sync_info["sync_options"]["mirror"]
)
if self.optimize:
previous_sync_info = defaultdict(dict, self.previous_repo_version.info)
if not previous_sync_info["remote_options"] == self.sync_info["remote_options"]:
log.info(_("Setting optimize=False since the remote options have changed."))
self.optimize = False
if mirror and not previous_sync_info["sync_options"]["mirror"]:
log.info(_("Setting optimize=False since this sync switches to mirror=True."))
self.optimize = False

async def run(self):
"""
Expand Down Expand Up @@ -618,7 +620,7 @@ async def _handle_distribution(self, distribution):
release_file = await self._create_unit(release_file_dc)
if release_file is None:
return
if self.optimize and self.sync_options_unchanged:
if self.optimize:
previous_release_file = await _get_previous_release_file(
self.previous_repo_version, distribution
)
Expand Down Expand Up @@ -899,7 +901,7 @@ async def _handle_package_index(
else:
raise NoPackageIndexFile(relative_dir=package_index_dir)

if self.optimize and self.sync_options_unchanged:
if self.optimize:
previous_package_index = await _get_previous_package_index(
self.previous_repo_version, relative_path
)
Expand Down

0 comments on commit 73a26ab

Please sign in to comment.