From c2fb97d586e8a2f4383823a36361207285d94d4d Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sat, 1 Sep 2018 20:05:30 +0200 Subject: lib/mysql-functions: exit early from mysql_sort_versions() if all versions are ordered already --- lib/mysql-functions | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/mysql-functions b/lib/mysql-functions index 9fe0984..c0f7790 100755 --- a/lib/mysql-functions +++ b/lib/mysql-functions @@ -1179,14 +1179,28 @@ mysql_update_versions_ordering() { ) } -# mysql_sort_versions -# sort the table of versions +# mysql_sort_versions [-f] +# sort the table of versions, iff versions without order exist or -f was +# given + mysql_sort_versions() { ( # new shell is intentional tmp_file=$( mktemp "tmp.mysql_sort_versions.XXXXXXXXXX" --tmpdir ) trap 'rm "${tmp_file}"' EXIT + if [ "x$1" != 'x-f' ] && \ + { + printf 'SELECT' + printf ' COUNT(1)' + printf ' FROM `versions`' + printf ' WHERE `versions`.`order` IS NULL' + } | \ + mysql_run_query | \ + grep -qxF '0'; then + # nothing to do + return 0 + fi { printf 'SELECT ' printf '`versions`.`%s`,' \ -- cgit v1.2.3-70-g09d2