Skip to content

Commit 737b835

Browse files
authored
Optimize get_artifacts_for_build() with regex filtering (#4297)
Introduces regex-based filtering directly in the API to improve performance and reduce number of calls to ab api server.
1 parent ffd55e8 commit 737b835

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/clusterfuzz/_internal/platforms/android/fetch_artifact.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import json
2020
import os
2121
import re
22+
from typing import List
23+
from typing import Optional
2224

2325
import apiclient
2426
from oauth2client.service_account import ServiceAccountCredentials
@@ -119,10 +121,22 @@ def download_artifact(client, bid, target, attempt_id, name, output_directory,
119121
return output_path
120122

121123

122-
def get_artifacts_for_build(client, bid, target, attempt_id='latest'):
124+
def get_artifacts_for_build(client,
125+
bid: str,
126+
target: str,
127+
attempt_id: str = 'latest',
128+
regexp: Optional[str] = None) -> List[str]:
123129
"""Return list of artifacts for a given build."""
124-
request = client.buildartifact().list(
125-
buildId=bid, target=target, attemptId=attempt_id)
130+
if not regexp:
131+
request = client.buildartifact().list(
132+
buildId=bid, target=target, attemptId=attempt_id)
133+
else:
134+
request = client.buildartifact().list(
135+
buildId=bid,
136+
target=target,
137+
attemptId=attempt_id,
138+
nameRegexp=regexp,
139+
maxResults=100)
126140

127141
request_str = (f'{request.uri}, {request.method}, '
128142
f'{request.body}, {request.methodId}')
@@ -239,7 +253,7 @@ def get(bid, target, regex, output_directory, output_filename=None):
239253
def run_script(client, bid, target, regex, output_directory, output_filename):
240254
"""Download artifacts as specified."""
241255
artifacts = get_artifacts_for_build(
242-
client=client, bid=bid, target=target, attempt_id='latest')
256+
client=client, bid=bid, target=target, attempt_id='latest', regexp=regex)
243257
if not artifacts:
244258
logs.error(f'Artifact could not be fetched for target {target}, '
245259
f'build id {bid}.')

0 commit comments

Comments
 (0)