Your question is Optimizing Code Performance. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
At Azumo, your team runs a nightly job that scans a shared build log and reports how many builds failed for each client project, then waits for any builds still in progress to finish. The script below works, but it has gotten noticeably slower as the number of tracked projects and builds has grown.
import time
def summarize_build_logs(log_path, project_names, blocked_projects):
report = ""
for project in project_names:
if project in blocked_projects:
continue
with open(log_path) as f:
content = f.read()
lines = content.split("
")
failures = 0
for line in lines:
if project in line and "FAILED" in line:
failures += 1
report += project + ": " + str(failures) + " failures
"
return report
def fetch_build_status(build_id):
time.sleep(1)
return "done"
def wait_for_builds(build_ids):
results = []
for build_id in build_ids:
status = fetch_build_status(build_id)
while status != "done":
status = fetch_build_status(build_id)
results.append(status)
return results
Explain what would make this slow in production and how you'd change it so it scales to hundreds of client projects and builds. This is a discussion question, so describe your changes and why they help rather than submitting a fixed file.