Skip to content

Commit d2f1f74

Browse files
committed
Revert "Improve performance by fetching repositories in parallel"
This reverts commit 45d595d.
1 parent d222871 commit d2f1f74

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

gh.sh

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,23 @@ item=$(
3636
EOF
3737
)
3838

39-
# Always fetch in parallel and merge results (user repos + search results if query present)
40-
41-
tmp_user=$(mktemp)
42-
tmp_search=$(mktemp)
43-
cleanup() { rm -f "$tmp_user" "$tmp_search"; }
44-
trap cleanup EXIT
45-
46-
# User repos (filtered locally with grep if query provided)
47-
(
48-
gh api /user/repos --method GET \
49-
-f sort=pushed \
39+
repos=$(gh api /user/repos --method GET \
40+
-f sort=pushed \
41+
--hostname "$API_HOST" \
42+
--cache "$CACHE_USER_REPOS" \
43+
--paginate \
44+
--jq ".[] | $item" | grep -i "$query")
45+
46+
if [[ -z "$repos" ]]; then
47+
repos=$(gh api /search/repositories --method GET \
5048
--hostname "$API_HOST" \
51-
--cache "$CACHE_USER_REPOS" \
52-
--paginate \
53-
--jq ".[] | $item" | { if [[ -n "$query" ]]; then grep -i "$query" || true; else cat; fi; } >"$tmp_user"
54-
) &
55-
pid_user=$!
56-
57-
# Search endpoint (only if query provided, otherwise skip to save API calls)
58-
if [[ -n "$query" ]]; then
59-
(
60-
gh api /search/repositories --method GET \
61-
--hostname "$API_HOST" \
62-
-f q="$query in:name archived:false" \
63-
-F per_page=9 \
64-
-f sort=pushed \
65-
--cache "$CACHE_SEARCH_REPOS" \
66-
--jq ".items.[] | $item" >"$tmp_search"
67-
) &
68-
pid_search=$!
69-
fi
70-
71-
wait "$pid_user" 2>/dev/null || true
72-
if [[ -n "$pid_search" ]]; then
73-
wait "$pid_search" 2>/dev/null || true
49+
-f q="$query in:name archived:false" \
50+
-F per_page=9 \
51+
-f sort=pushed \
52+
--cache "$CACHE_SEARCH_REPOS" \
53+
--jq ".items.[] | $item")
7454
fi
7555

76-
# Combine, remove blanks, unique by uid (id) preserving first occurrence
77-
items_array=$(cat "$tmp_user" "$tmp_search" 2>/dev/null | awk 'NF' | jq -s 'unique_by(.uid)')
56+
items=$(echo -n "$repos" | tr '\n', ',' | sed 's/,$//')
7857

79-
echo -n "{\"items\":$items_array}"
58+
echo -n "{\"items\":[$items]}"

0 commit comments

Comments
 (0)