Move projects.last_activity_at and projects.last_repository_updated_at to the project_statistics table
The column projects.last_activity_at is updated when certain events are created, at most once an hour. However, the column projects.last_repository_updated_at is updated for every push event. This means that if you push 1000 times in a row that will result in 1000 updates. This is not ideal because the projects table is fairly wide (= lots of columns), has a lot of data and has a lot of indexes.
To alleviate some of the pain here we should move both columns to the project_statistics table. This won't reduce the number of UPDATEs, but it will put less pressure on the system since updating project_statistics is cheaper.
The migration process for this is fairly straightforward:
- Add the columns to
project_statisticswith a default value ofNULL - Deploy code that uses these new columns
We don't need to migrate over the timestamps since this data will be updated as new events are created automatically. This saves us from having to update 1.5 - 2 million project_statistics rows.