@@ -155,56 +155,56 class Repository::Git < Repository | |||||
155 | end |
|
155 | end | |
156 |
|
156 | |||
157 | def save_revisions(prev_db_heads, repo_heads) |
|
157 | def save_revisions(prev_db_heads, repo_heads) | |
158 |
|
|
158 | h = {} | |
159 |
|
|
159 | opts = {} | |
160 |
|
|
160 | opts[:reverse] = true | |
161 |
|
|
161 | opts[:excludes] = prev_db_heads | |
162 |
|
|
162 | opts[:includes] = repo_heads | |
163 |
|
163 | |||
164 |
|
|
164 | revisions = scm.revisions('', nil, nil, opts) | |
165 |
|
|
165 | return if revisions.blank? | |
166 |
|
166 | |||
167 |
|
|
167 | # Make the search for existing revisions in the database in a more sufficient manner | |
168 |
|
|
168 | # This is replacing the one-after-one queries. | |
169 |
|
|
169 | # Find all revisions, that are in the database, and then remove them from the revision array. | |
170 |
|
|
170 | # Then later we won't need any conditions for db existence. | |
171 |
|
|
171 | # Query for several revisions at once, and remove them from the revisions array, if they are there. | |
172 |
|
|
172 | # Do this in chunks, to avoid eventual memory problems (in case of tens of thousands of commits). | |
173 |
|
|
173 | # If there are no revisions (because the original code's algoritm filtered them), | |
174 |
|
|
174 | # then this part will be stepped over. | |
175 |
|
|
175 | # We make queries, just if there is any revision. | |
176 |
|
|
176 | limit = 100 | |
177 |
|
|
177 | offset = 0 | |
178 |
|
|
178 | revisions_copy = revisions.clone # revisions will change | |
179 |
|
|
179 | while offset < revisions_copy.size | |
180 |
|
|
180 | recent_changesets_slice = changesets.find( | |
181 | :all, |
|
181 | :all, | |
182 | :conditions => [ |
|
182 | :conditions => [ | |
183 | 'scmid IN (?)', |
|
183 | 'scmid IN (?)', | |
184 | revisions_copy.slice(offset, limit).map{|x| x.scmid} |
|
184 | revisions_copy.slice(offset, limit).map{|x| x.scmid} | |
185 | ] |
|
185 | ] | |
186 | ) |
|
186 | ) | |
187 |
|
|
187 | # Subtract revisions that redmine already knows about | |
188 |
|
|
188 | recent_revisions = recent_changesets_slice.map{|c| c.scmid} | |
189 |
|
|
189 | revisions.reject!{|r| recent_revisions.include?(r.scmid)} | |
190 |
|
|
190 | offset += limit | |
191 |
|
|
191 | end | |
192 |
|
192 | |||
193 |
|
|
193 | revisions.each do |rev| | |
194 |
|
|
194 | transaction do | |
195 |
|
|
195 | # There is no search in the db for this revision, because above we ensured, | |
196 |
|
|
196 | # that it's not in the db. | |
197 |
|
|
197 | db_saved_rev = save_revision(rev) | |
198 |
|
|
198 | parents = {} | |
199 |
|
|
199 | parents[db_saved_rev] = rev.parents unless rev.parents.nil? | |
200 |
|
|
200 | parents.each do |ch, chparents| | |
201 |
|
|
201 | ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact | |
202 | end |
|
|||
203 | end |
|
202 | end | |
204 | end |
|
203 | end | |
205 | h["heads"] = repo_heads.dup |
|
204 | end | |
206 | merge_extra_info(h) |
|
205 | h["heads"] = repo_heads.dup | |
207 | self.save |
|
206 | merge_extra_info(h) | |
|
207 | self.save | |||
208 | end |
|
208 | end | |
209 | private :save_revisions |
|
209 | private :save_revisions | |
210 |
|
210 |
General Comments 0
You need to be logged in to leave comments.
Login now