Skip to content

Commit

Permalink
Optimize get_artifacts_for_build() with regex filtering
Browse files Browse the repository at this point in the history
Introduces regex-based filtering directly in the API to improve performance and reduce number of calls to ab api server.
  • Loading branch information
aditya-wazir committed Oct 8, 2024
1 parent d155aac commit b115c53
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/clusterfuzz/_internal/platforms/android/fetch_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,19 @@ def download_artifact(client, bid, target, attempt_id, name, output_directory,
return output_path


def get_artifacts_for_build(client, bid, target, attempt_id='latest'):
def get_artifacts_for_build(client, bid, target, attempt_id='latest',
regexp=''):
"""Return list of artifacts for a given build."""
request = client.buildartifact().list(
buildId=bid, target=target, attemptId=attempt_id)
if regexp == '':
request = client.buildartifact().list(
buildId=bid, target=target, attemptId=attempt_id)
else:
request = client.buildartifact().list(
buildId=bid,
target=target,
attemptId=attempt_id,
nameRegexp=regexp,
maxResults=100)

request_str = (f'{request.uri}, {request.method}, '
f'{request.body}, {request.methodId}')
Expand Down Expand Up @@ -238,7 +247,7 @@ def get(bid, target, regex, output_directory, output_filename=None):
def run_script(client, bid, target, regex, output_directory, output_filename):
"""Download artifacts as specified."""
artifacts = get_artifacts_for_build(
client=client, bid=bid, target=target, attempt_id='latest')
client=client, bid=bid, target=target, attempt_id='latest', regexp=regex)
if not artifacts:
logs.error(f'Artifact could not be fetched for target {target}, '
f'build id {bid}.')
Expand Down

0 comments on commit b115c53

Please sign in to comment.