Fix states cache method of checking if state is fresh

When we get last build status for a repository or a branch we use the id
column to determine which build is the last one. In states cache builds
were checked based on the finished_at column, which may have cause cache
to be out of sync.

Piotr Sarnacki authored and committed

Nothing here #3728.1 passed

  • Ran for
AMD64
no language set
Git