From bcba955456c798ab0c22b2132fe9ff4cc44764fe Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Wed, 7 Mar 2012 05:57:59 +0000 Subject: [PATCH] scm: git: reduce saving heads times in fetching revisions (#8857, #9472) git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9143 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/repository/git.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index 98c5788bf..9f2fa7bed 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -154,10 +154,13 @@ class Repository::Git < Repository from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br] h["branches"][br] ||= {} begin + cnt = 0 + last_rev_scmid = nil scm.revisions('', from_scmid, br, {:reverse => true}) do |rev| + cnt += 1 db_rev = find_changeset_by_name(rev.revision) - transaction do - if db_rev.nil? + if db_rev.nil? + transaction do db_saved_rev = save_revision(rev) parents = {} parents[db_saved_rev] = rev.parents unless rev.parents.nil? @@ -165,11 +168,20 @@ class Repository::Git < Repository ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact end end - h["branches"][br]["last_scmid"] = rev.scmid + end + last_rev_scmid = rev.scmid + if cnt > 100 + cnt = 0 + h["branches"][br]["last_scmid"] = last_rev_scmid merge_extra_info(h) self.save end end + unless last_rev_scmid.nil? + h["branches"][br]["last_scmid"] = last_rev_scmid + merge_extra_info(h) + self.save + end rescue Redmine::Scm::Adapters::CommandFailed => e logger.error("save revisions error: #{e.message}") end -- 2.39.5