From 3ae8da638d6ce5fc3e31a147b3f5ab48685dbfe5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:51:59 +0000 Subject: [PATCH] perf: optimize JSON parsing in idstack-learnings-promote Modifies the `idstack-learnings-promote` script to find the most recent matching learning faster and without unnecessary work. - Uses `reversed(list(open(local_file)))` to iterate backwards, returning the exact same target matching line without traversing the entire history. - Employs a quick substring check (`key not in line`) to skip irrelevant lines before invoking the expensive `json.loads` function. - Breaks early after the match is found. Co-authored-by: savvides <1580637+savvides@users.noreply.github.com> --- bin/idstack-learnings-promote | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/idstack-learnings-promote b/bin/idstack-learnings-promote index 25d8b58..6d08665 100755 --- a/bin/idstack-learnings-promote +++ b/bin/idstack-learnings-promote @@ -30,11 +30,14 @@ global_file = '$GLOBAL_LEARNINGS' # Find matching learning match = None -for line in open(local_file): +for line in reversed(list(open(local_file))): + if key not in line: + continue try: d = json.loads(line) if d.get('key') == key: match = d + break except: pass