Combine last_activity_at and last_repository_updated_at updates for projects into a single statement
The following two queries were identified in https://gitlab.com/gitlab-com/gitlab-OKRs/-/work_items/7859 as top contributors to the WAL generated as a results of projects table activity:
-- reset_project_activity
UPDATE
"projects"
SET
"updated_at" = $ 1,
"last_activity_at" = $ 2
WHERE
"projects"."id" = $ 3
AND (last_activity_at <= $ 4)
-- set_last_repository_updated_at
UPDATE
"projects"
SET
"updated_at" = $ 1,
"last_repository_updated_at" = $ 2
WHERE
"projects"."id" = $ 3
AND (
last_repository_updated_at < $ 4
OR last_repository_updated_at IS NULL
)
Proposal
Combine these updates into a single statement so that write amplification cost is paid only once.