Don't override newer versions of cached markdown in the database
GitLab caches markdown in the postgres database.
In some cases, this cached markdown is stored on critically performance-important tables, such as namespaces
.
When the version of markdown is updated, every rails view that renders markdown will update the cached version to match the version it is running.
This causes a tremendous amount of crunch in the database, resulting in dead-tuples. This in turn can have an impact on database performance, particularly on the critical tables.
This is exacerbated by production and canary continually overwriting the over version each time the page is viewed from the other stage gitlab-com/gl-infra/production#4481 (comment 568210146). We call this "flip-flopping".
For details:
Proposal
Only write the cached markdown back to postgres if the version number stored in the database is lower than the current version.
This will reduce the flip-flopping.
Risk
In the event of a revert, the database will not be updated and markdown caching will effectively stop working until the new version is redeployed. There are some workarounds for this.