]> source.dussan.org Git - gitea.git/commit
Move from `max( id )` to `max( index )` for latest commit statuses (#30076)
authorYR Chen <stevapple@icloud.com>
Thu, 28 Mar 2024 08:01:15 +0000 (16:01 +0800)
committerGitHub <noreply@github.com>
Thu, 28 Mar 2024 08:01:15 +0000 (16:01 +0800)
commit7443a10fc3d722d3326a0cb7b15b208f907c72d7
tree6a099e6fbd8a114fb4b260e96b832bae89c28247
parent0d5abe3454c73f11d90d2809af0949a0e0636c22
Move from `max( id )` to `max( index )` for latest commit statuses (#30076)

This PR replaces the use of `max( id )`, and instead using ``max(
`index` )`` for determining the latest commit status. Building business
logic over an `auto_increment` primary key like `id` is risky and
there’re already plenty of discussions on the Internet.

There‘s no guarantee for `auto_increment` values to be monotonic,
especially upon failures or with a cluster. In the specific case, we met
the problem of commit statuses being outdated when using TiDB as the
database. As [being
documented](https://docs.pingcap.com/tidb/stable/auto-increment),
`auto_increment` values assigned to an `insert` statement will only be
monotonic on a per server (node) basis.

Closes #30074.
models/git/commit_status.go