Make sure that the cached Job build status is always synchronized.

* src/sql/upgrade-10.sql: New file.
* Makefile.am (dist_sql_DATA): Update it.
* src/schema.sql (update_job_status): New function,
(build_status): new trigger.
This commit is contained in:
Mathieu Othacehe 2021-04-28 21:18:18 +02:00
parent 8d5b0cc523
commit 97cf5b56d5
No known key found for this signature in database
GPG Key ID: 8354763531769CA6
3 changed files with 33 additions and 1 deletions

View File

@ -96,7 +96,8 @@ dist_sql_DATA = \
src/sql/upgrade-6.sql \
src/sql/upgrade-7.sql \
src/sql/upgrade-8.sql \
src/sql/upgrade-9.sql
src/sql/upgrade-9.sql \
src/sql/upgrade-10.sql
dist_css_DATA = \
src/static/css/choices.min.css \

View File

@ -131,6 +131,20 @@ CREATE INDEX Builds_status_ts_id on Builds(status DESC, timestamp DESC, id ASC);
CREATE INDEX Builds_priority_timestamp on Builds(priority ASC, timestamp DESC);
CREATE INDEX Builds_weather_evaluation ON Builds (weather, evaluation);
-- Make sure that the cached Job build status is always synchronized with the
-- matching build status.
CREATE FUNCTION update_job_status()
RETURNS TRIGGER AS $$
BEGIN
UPDATE Jobs SET status = NEW.status WHERE Jobs.build = NEW.id;
RETURN null;
END
$$ LANGUAGE plpgsql;
CREATE TRIGGER build_status AFTER UPDATE ON Builds
FOR EACH ROW
EXECUTE PROCEDURE update_job_status();
CREATE INDEX Jobs_name ON Jobs (name);
CREATE INDEX Jobs_system_status ON Jobs (system, status);
CREATE INDEX Jobs_build ON Jobs (build); --speeds up delete cascade.

17
src/sql/upgrade-10.sql Normal file
View File

@ -0,0 +1,17 @@
BEGIN TRANSACTION;
-- Make sure that the cached Job build status is always synchronized with the
-- matching build status.
CREATE FUNCTION update_job_status()
RETURNS TRIGGER AS $$
BEGIN
UPDATE Jobs SET status = NEW.status WHERE Jobs.build = NEW.id;
RETURN null;
END
$$ LANGUAGE plpgsql;
CREATE TRIGGER build_status AFTER UPDATE ON Builds
FOR EACH ROW
EXECUTE PROCEDURE update_job_status();
COMMIT;