summaryrefslogtreecommitdiff
path: root/lib/mysql-functions
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-09-28 12:27:20 +0200
committerErich Eckner <git@eckner.net>2018-09-28 12:27:20 +0200
commitd79aaf42d898df61254d016a9f8d71e158501fe5 (patch)
treef0f7250ff7e740e46fd01a80f000736940fe5061 /lib/mysql-functions
parenta52c4adef7a061e48449b940e4444a017715b3aa (diff)
downloadbuilder-d79aaf42d898df61254d016a9f8d71e158501fe5.tar.xz
lib/mysql-functions: mysql_cleanup() now also cleans up the priorities of build_assignments
Diffstat (limited to 'lib/mysql-functions')
-rwxr-xr-xlib/mysql-functions28
1 files changed, 28 insertions, 0 deletions
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'
}