From 845ba9d1537eb1012bb0d448265b5346ef14d2d3 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 23 Feb 2018 08:27:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20if=20Mirrors=20repo=20no=20content=20is?= =?UTF-8?q?=20fetched,=20updated=20time=20should=20not=20b=E2=80=A6=20(#35?= =?UTF-8?q?51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: if Mirrors repo no content is fetched, updated time should not be changed * fix: sync update time from mirror repo. * fix: one single session. * update comment. Signed-off-by: Bo-Yi Wu --- models/repo_mirror.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/models/repo_mirror.go b/models/repo_mirror.go index 197889e19..97fe2406c 100644 --- a/models/repo_mirror.go +++ b/models/repo_mirror.go @@ -244,6 +244,8 @@ func MirrorUpdate() { // SyncMirrors checks and syncs mirrors. // TODO: sync more mirrors at same time. func SyncMirrors() { + sess := x.NewSession() + defer sess.Close() // Start listening on new sync requests. for repoID := range MirrorQueue.Queue() { log.Trace("SyncMirrors [repo_id: %v]", repoID) @@ -260,10 +262,22 @@ func SyncMirrors() { } m.ScheduleNextUpdate() - if err = UpdateMirror(m); err != nil { + if err = updateMirror(sess, m); err != nil { log.Error(4, "UpdateMirror [%s]: %v", repoID, err) continue } + + // Get latest commit date and update to current repository updated time + commitDate, err := git.GetLatestCommitTime(m.Repo.RepoPath()) + if err != nil { + log.Error(2, "GetLatestCommitDate [%s]: %v", m.RepoID, err) + continue + } + + if _, err = sess.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", commitDate.Unix(), m.RepoID); err != nil { + log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err) + continue + } } }