From d79aaf42d898df61254d016a9f8d71e158501fe5 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 28 Sep 2018 12:27:20 +0200 Subject: lib/mysql-functions: mysql_cleanup() now also cleans up the priorities of build_assignments --- lib/mysql-functions | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/mysql-functions') diff --git a/lib/mysql-functions b/lib/mysql-functions index 5888251..1e609f5 100755 --- a/lib/mysql-functions +++ b/lib/mysql-functions @@ -909,6 +909,34 @@ mysql_cleanup() { printf ' AND (`build_slaves`.`last_action` IS NOT NULL' printf ' OR `build_slaves`.`logged_lines` IS NOT NULL' printf ' OR `build_slaves`.`trials` IS NOT NULL);\n' + # shrink the priorities + printf 'CREATE TEMPORARY TABLE `ps%s`(`old_p` SMALLINT, `new_p` SMALLINT, UNIQUE KEY `old_p`(`old_p`));\n' \ + '' '_2' '_3' + printf 'INSERT INTO `ps`(`old_p`) VALUES (0);\n' + printf 'INSERT IGNORE INTO `ps`(`old_p`)' + printf ' SELECT `build_assignments`.`priority`' + printf ' FROM `build_assignments`;\n' + printf 'INSERT INTO `ps_%s`(`old_p`) SELECT `ps`.`old_p` FROM `ps`;\n' \ + '2' '3' + printf 'UPDATE `ps`' + printf ' LEFT JOIN (' + printf 'SELECT' + printf ' `ps_2`.`old_p` AS `limit_p`,' + printf 'COUNT(`ps_3`.`old_p`) AS `count_p`' + printf ' FROM `ps_2`' + printf ' JOIN `ps_3`' + printf ' ON `ps_3`.`old_p`<`ps_2`.`old_p`' + printf ' GROUP BY `ps_2`.`old_p`' + printf ') AS `ps_q`' + printf ' ON `ps_q`.`limit_p`=`ps`.`old_p`' + printf ' SET `ps`.`new_p`=IFNULL(`ps_q`.`count_p`,0)' + printf ';\n' + printf 'UPDATE `build_assignments`' + printf ' JOIN `ps`' + printf ' ON `build_assignments`.`priority`=`ps`.`old_p`' + printf ' SET `build_assignments`.`priority`=`ps`.`new_p`;\n' + printf 'DROP TEMPORARY TABLE `ps%s`;\n' \ + '' '_2' '_3' } | \ mysql_run_query 'unimportant' } -- cgit v1.2.3-54-g00ecf