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

perf: use lpop with count and don't fetch upload in Upload task #707

Merged
merged 1 commit into from
Sep 16, 2024
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
18 changes: 14 additions & 4 deletions tasks/tests/unit/test_upload_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,24 @@
return res.encode()
return res

def lpop(self, key):
def lpop(self, key, count=None):
list = self.lists.get(key)
if not list:
return None

res = list.pop(0)
if list == []:
del self.lists[key]
res = None
if count:
res = []
for _ in range(count):
res.append(list.pop(0))
if list == []:
del self.lists[key]
break
else:
res = list.pop(0)
if list == []:
del self.lists[key]

Check warning on line 104 in tasks/tests/unit/test_upload_task.py

View check run for this annotation

Codecov Notifications / codecov/patch

tasks/tests/unit/test_upload_task.py#L102-L104

Added lines #L102 - L104 were not covered by tests

return res

def delete(self, key):
Expand Down
11 changes: 5 additions & 6 deletions tasks/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ def arguments_list(self):
"""
uploads_list_key = self.upload_location
log.debug("Fetching arguments from redis %s", uploads_list_key)
while arguments := self.redis_connection.lpop(uploads_list_key):
yield loads(arguments)
while arguments := self.redis_connection.lpop(uploads_list_key, count=50):
for arg in arguments:
yield loads(arg)

def normalize_arguments(self, commit: Commit, arguments: dict[str, Any]):
"""
Expand Down Expand Up @@ -502,15 +503,13 @@ def run_impl_within_lock(
for arguments in upload_context.arguments_list():
normalized_arguments = upload_context.normalize_arguments(commit, arguments)
if "upload_id" in normalized_arguments:
upload = report_service.fetch_report_upload(
commit_report, normalized_arguments["upload_id"]
)
normalized_arguments["upload_pk"] = normalized_arguments["upload_id"]
else:
upload = report_service.create_report_upload(
normalized_arguments, commit_report
)

normalized_arguments["upload_pk"] = upload.id_
normalized_arguments["upload_pk"] = upload.id_
argument_list.append(normalized_arguments)

if argument_list:
Expand Down
Loading