# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1282223415 -32400
# Node ID 12d3eef60fc7423faf65a57322278b326076d179
# Parent  cd4ab8b2a573bafd7c794d9b9ca1044373af0c1c
model: repository: list up sub-directory changes by latest_changesets (refs #6159)

 * filter by changes.path = "..." OR changes.path LIKE ".../%".
 * JOIN changes for path condition; then SELECT DISTINCT changesets.*
   to strip duplicated records.
 * ORDER BY statements are declared by 'has_many :changesets, :order => ...',
   so removes the duplicated lines.

diff --git a/app/models/repository.rb b/app/models/repository.rb
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -105,14 +105,14 @@ class Repository < ActiveRecord::Base
   # Default behaviour is to search in cached changesets
   def latest_changesets(path, rev, limit=10)
     if path.blank?
-      changesets.find(:all, :include => :user,
-                            :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
-                            :limit => limit)
+      changesets.find(:all, :include => :user, :limit => limit)
     else
-      changes.find(:all, :include => {:changeset => :user}, 
-                         :conditions => ["path = ?", path.with_leading_slash],
-                         :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
-                         :limit => limit).collect(&:changeset)
+      changesets.find(:all, :select => "DISTINCT #{Changeset.table_name}.*",
+                      :joins => :changes,
+                      :conditions => ["#{Change.table_name}.path = ? OR #{Change.table_name}.path LIKE ?",
+                                      path.with_leading_slash,
+                                      "#{path.with_leading_slash.gsub('%', '%%')}/%"],
+                      :include => :user, :limit => limit)
     end
   end
     
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1282226774 -32400
# Node ID a964fe6b8c670aebf44d2123fb071c3dfd62af72
# Parent  12d3eef60fc7423faf65a57322278b326076d179
model: repository: subversion: make latest_changesets query database (refs #6159)

diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb
--- a/app/models/repository/subversion.rb
+++ b/app/models/repository/subversion.rb
@@ -31,8 +31,8 @@ class Repository::Subversion < Repositor
   end
 
   def latest_changesets(path, rev, limit=10)
-    revisions = scm.revisions(path, rev, nil, :limit => limit)
-    revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
+    path = "#{relative_url}/#{path}".gsub(%r|/+|, '/') unless path.blank?
+    super(path, rev, limit)
   end
   
   # Returns a path relative to the url of the repository
