Skip to content

Commit c342244

Browse files
committed
refactor saving
1 parent 9fd25af commit c342244

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/bkg.sh

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,45 +148,35 @@ main() {
148148
)" | sort -u >all_owners_in_db
149149
grep -vFxf all_owners_in_db "$BKG_OWNERS" >owners.tmp
150150
mv owners.tmp "$BKG_OWNERS"
151-
grep -vFxf all_owners_in_db "$connections" >"$temp_connections"
152151

153152
if [[ "$pkg_left" == "0" || "${db_size_curr::-4}" == "${db_size_prev::-4}" ]]; then
153+
BKG_BATCH_FIRST_STARTED=$today
154154
set_BKG BKG_BATCH_FIRST_STARTED "$today"
155155
rm -f packages_to_update
156156
\cp packages_all packages_to_update
157157
: >packages_already_updated
158158
fi
159159

160-
# owners that have to be updated
161-
bash get.sh "$BKG_INDEX_DIR" "$BKG_INDEX" "$BKG_BATCH_FIRST_STARTED" 2>/dev/null >>"$temp_connections"
162-
163160
: >all_owners_tu
164161
[ ! -s packages_to_update ] || echo "$(
165162
awk -F'|' '{print "0/"$2}' packages_to_update
166163
awk -F'|' '{print $1"/"$2}' packages_to_update
167164
awk -F'|' '{print $2}' packages_to_update
168165
)" | sort -u >all_owners_tu
169166

170-
echo "$(
171-
echo "0/$GITHUB_OWNER"
172-
173-
# new connections
174-
cat "$temp_connections"
175-
176-
# connections that have to be updated
177-
grep -Fxf all_owners_tu "$connections"
178-
179-
# requests
180-
cat "$BKG_OWNERS"
181-
)" >"$BKG_OWNERS"
167+
{
168+
! grep -qP "\b$GITHUB_OWNER\b" all_owners_tu || echo "0/$GITHUB_OWNER"
169+
grep -vFxf all_owners_in_db "$connections"
170+
grep -Fxf all_owners_tu "$connections"
171+
} >"$temp_connections"
182172

183173
rm -f all_owners_in_db all_owners_tu
174+
clean_owners "$temp_connections"
184175
clean_owners "$BKG_OWNERS"
185-
len_conn=$(wc -l <"$connections")
186-
head -n $(( len_conn < 1000 ? len_conn + 1000 : len_conn * 3 / 2 )) "$BKG_OWNERS" | env_parallel --lb save_owner
187-
awk -F'|' '{print $1"/"$2}' packages_to_update | sort -uR 2>/dev/null | head -n1000 | env_parallel --lb save_owner
188-
parallel "sed -i '\,^{}$,d' $BKG_OWNERS" ::: "$(sed 's/"/\\"/g' "$connections")"
189-
sed -i '/^0\//d' "$BKG_OWNERS"
176+
# self > stars > 1000 submitted > stale
177+
cat "$temp_connections" | env_parallel --lb save_owner
178+
head -n 1000 "$BKG_OWNERS" | env_parallel --lb save_owner
179+
bash get.sh "$BKG_INDEX_DIR" "$BKG_INDEX" "$BKG_BATCH_FIRST_STARTED" 2>/dev/null | env_parallel --lb save_owner
190180
set_BKG BKG_DIFF "$db_size_curr"
191181
fi
192182
else

0 commit comments

Comments
 (0)