Skip to content

gitserver: use same value for LastFetched in DB and API

Administrator requested to merge k/gitserver-last-changed into main

Created by: keegancsmith

We used time.Now() for the last fetched value we upsert into the database. We also have repoLastFetched which is based on the timestamp of HEAD. This commit unifies them to the timestamp of HEAD.

The intention behind this commit is to make it easier to add in last_changed, which is also based on the timestamp of a file.

This commit contains some minor refactors to make it easier to add in a new field to record. We introduce a struct for the params to SetLastFetched (to avoid having multiple timestamps). We also need to move when we update the DB in a clone to after it is renamed into the destination.

Test Plan: Ran local environment, nothing exploded. Also confirmed before running that the timestamps in the database and HEAD aligned:

$ find ~/.sourcegraph/repos/ -name HEAD | xargs stat | grep Change
Change: 2021-10-05 11:53:51.994007716 +0200
Change: 2021-10-05 11:35:56.242565241 +0200

$ psql -c 'select last_fetched from gitserver_repos'
         last_fetched
-------------------------------
 2021-10-05 09:53:52.02386+00
 2021-10-05 09:35:56.246435+00
(2 rows)

Merge request reports

Loading