]> source.dussan.org Git - redmine.git/commitdiff
scm: git: reduce saving heads times in fetching revisions (#8857, #9472)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 7 Mar 2012 05:57:59 +0000 (05:57 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 7 Mar 2012 05:57:59 +0000 (05:57 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9143 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository/git.rb

index 98c5788bfe4d1ea3f588948e71b17e993ad48145..9f2fa7bed095dbd60023c58ebba608eb5070a693 100644 (file)
@@ -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