@@ -657,6 +657,7 @@ type AccessibleReposEnvironment interface {
657657 Repos (page , pageSize int ) ([]* Repository , error )
658658 MirrorRepos () ([]* Repository , error )
659659 AddKeyword (keyword string )
660+ SetSort (SearchOrderBy )
660661}
661662
662663type accessibleReposEnv struct {
@@ -665,6 +666,7 @@ type accessibleReposEnv struct {
665666 teamIDs []int64
666667 e Engine
667668 keyword string
669+ orderBy SearchOrderBy
668670}
669671
670672// AccessibleReposEnv an AccessibleReposEnvironment for the repositories in `org`
@@ -683,6 +685,7 @@ func (org *User) accessibleReposEnv(e Engine, userID int64) (AccessibleReposEnvi
683685 userID : userID ,
684686 teamIDs : teamIDs ,
685687 e : e ,
688+ orderBy : SearchOrderByRecentUpdated ,
686689 }, nil
687690}
688691
@@ -722,8 +725,8 @@ func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) {
722725 Table ("repository" ).
723726 Join ("INNER" , "team_repo" , "`team_repo`.repo_id=`repository`.id" ).
724727 Where (env .cond ()).
725- GroupBy ("`repository`.id,`repository`.updated_unix" ).
726- OrderBy ("updated_unix DESC" ).
728+ GroupBy ("`repository`.id,`repository`." + strings . Fields ( string ( env . orderBy ))[ 0 ] ).
729+ OrderBy (string ( env . orderBy ) ).
727730 Limit (pageSize , (page - 1 )* pageSize ).
728731 Cols ("`repository`.id" ).
729732 Find (& repoIDs )
@@ -742,6 +745,7 @@ func (env *accessibleReposEnv) Repos(page, pageSize int) ([]*Repository, error)
742745
743746 return repos , env .e .
744747 In ("`repository`.id" , repoIDs ).
748+ OrderBy (string (env .orderBy )).
745749 Find (& repos )
746750}
747751
@@ -752,7 +756,7 @@ func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) {
752756 Join ("INNER" , "team_repo" , "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?" , true ).
753757 Where (env .cond ()).
754758 GroupBy ("`repository`.id, `repository`.updated_unix" ).
755- OrderBy ("updated_unix DESC" ).
759+ OrderBy (string ( env . orderBy ) ).
756760 Cols ("`repository`.id" ).
757761 Find (& repoIDs )
758762}
@@ -776,3 +780,7 @@ func (env *accessibleReposEnv) MirrorRepos() ([]*Repository, error) {
776780func (env * accessibleReposEnv ) AddKeyword (keyword string ) {
777781 env .keyword = keyword
778782}
783+
784+ func (env * accessibleReposEnv ) SetSort (orderBy SearchOrderBy ) {
785+ env .orderBy = orderBy
786+ }
0 commit comments