Skip to content

Commit e55eaa8

Browse files
appleboylafriks
authored andcommitted
if Mirrors repo no content is fetched, updated time should not be changed #3551 (#3565)
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 423c642 commit e55eaa8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

models/repo_mirror.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func MirrorUpdate() {
244244
// SyncMirrors checks and syncs mirrors.
245245
// TODO: sync more mirrors at same time.
246246
func SyncMirrors() {
247+
sess := x.NewSession()
248+
defer sess.Close()
247249
// Start listening on new sync requests.
248250
for repoID := range MirrorQueue.Queue() {
249251
log.Trace("SyncMirrors [repo_id: %v]", repoID)
@@ -260,10 +262,22 @@ func SyncMirrors() {
260262
}
261263

262264
m.ScheduleNextUpdate()
263-
if err = UpdateMirror(m); err != nil {
265+
if err = updateMirror(sess, m); err != nil {
264266
log.Error(4, "UpdateMirror [%s]: %v", repoID, err)
265267
continue
266268
}
269+
270+
// Get latest commit date and update to current repository updated time
271+
commitDate, err := git.GetLatestCommitTime(m.Repo.RepoPath())
272+
if err != nil {
273+
log.Error(2, "GetLatestCommitDate [%s]: %v", m.RepoID, err)
274+
continue
275+
}
276+
277+
if _, err = sess.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", commitDate.Unix(), m.RepoID); err != nil {
278+
log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err)
279+
continue
280+
}
267281
}
268282
}
269283

0 commit comments

Comments
 (0)