@@ -10,11 +10,15 @@ type RecommendOrg struct { | |||
Order int64 `xorm:"INDEX NOT NULL unique"` | |||
OrgID int64 `xorm:"INDEX NOT NULL unique"` | |||
CreatedUnix timeutil.TimeStamp `xorm:"created"` | |||
} | |||
Org *User `xorm:"-"` | |||
type RecommendOrgInfo struct { | |||
RecommendOrg `xorm:"extends"` | |||
User `xorm:"extends"` | |||
} | |||
type RecommendOrgList []*RecommendOrg | |||
type RecommendOrgInfoList []*RecommendOrgInfo | |||
func getRecommendOrgs(e Engine) (RecommendOrgList, error) { | |||
orgs := make(RecommendOrgList, 0, 10) | |||
@@ -27,6 +31,19 @@ func GetRecommendOrgs() (RecommendOrgList, error) { | |||
return getRecommendOrgs(x) | |||
} | |||
func getRecommendOrgInfos(e Engine) (RecommendOrgInfoList, error) { | |||
orgs := make(RecommendOrgInfoList, 0, 10) | |||
if err := e.Table(&RecommendOrg{}).Join("INNER", "`user`", "`user`.id = `recommend_org`.org_id"). | |||
OrderBy("recommend_org.order").Find(&orgs); err != nil { | |||
return orgs, err | |||
} | |||
return orgs, nil | |||
} | |||
func GetRecommendOrgInfos() (RecommendOrgInfoList, error) { | |||
return getRecommendOrgInfos(x) | |||
} | |||
func delRecommendOrgs(e Engine) error { | |||
sql := "delete from recommend_org" | |||
_, err := e.Exec(sql) | |||
@@ -1412,6 +1412,15 @@ func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) { | |||
return getRepositoriesByForkID(x, forkID) | |||
} | |||
func getALLRepositories(e Engine) ([]*Repository, error) { | |||
repos := make([]*Repository, 0, 1000) | |||
return repos, e.Find(&repos) | |||
} | |||
func GetAllRepositories() ([]*Repository, error) { | |||
return getALLRepositories(x) | |||
} | |||
func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) { | |||
repo.LowerName = strings.ToLower(repo.Name) | |||
@@ -2414,6 +2423,7 @@ func updateRepositoryCols(e Engine, repo *Repository, cols ...string) error { | |||
} | |||
// UpdateRepositoryCols updates repository's columns | |||
// Notice: it will update the updated_unix automatically, be careful to use this | |||
func UpdateRepositoryCols(repo *Repository, cols ...string) error { | |||
return updateRepositoryCols(x, repo, cols...) | |||
} | |||
@@ -2443,3 +2453,11 @@ func (repo *Repository) IncreaseCloneCnt() { | |||
return | |||
} | |||
func UpdateRepositoryCommitNum(repo *Repository) error { | |||
if _,err := x.Exec("UPDATE `repository` SET num_commit = ? where id = ?", repo.NumCommit, repo.ID); err != nil { | |||
return err | |||
} | |||
return nil | |||
} |
@@ -7,6 +7,7 @@ package routers | |||
import ( | |||
"bytes" | |||
"net/http" | |||
"strings" | |||
"code.gitea.io/gitea/models" | |||
@@ -146,6 +147,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { | |||
orderBy = models.SearchOrderByRecentUpdated | |||
} | |||
//todo:support other topics | |||
keyword := strings.Trim(ctx.Query("q"), " ") | |||
topicOnly := ctx.QueryBool("topic") | |||
ctx.Data["TopicOnly"] = topicOnly | |||
@@ -179,7 +181,15 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { | |||
pager.AddParam(ctx, "topic", "TopicOnly") | |||
ctx.Data["Page"] = pager | |||
ctx.HTML(200, opts.TplName) | |||
recommendOrgs, err := models.GetRecommendOrgInfos() | |||
if err != nil { | |||
log.Error("GetRecommendOrgInfos failed:%v", err.Error(), ctx.Data["MsgID"]) | |||
ctx.ServerError("GetRecommendOrgInfos", err) | |||
return | |||
} | |||
ctx.Data["RecommendOrgs"] = recommendOrgs | |||
ctx.HTML(http.StatusOK, opts.TplName) | |||
} | |||
// ExploreRepos render explore repositories page | |||
@@ -0,0 +1,37 @@ | |||
// Copyright 2020 The Gitea Authors. All rights reserved. | |||
// Use of this source code is governed by a MIT-style | |||
// license that can be found in the LICENSE file. | |||
package private | |||
import ( | |||
"gitea.com/macaron/macaron" | |||
"net/http" | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/log" | |||
) | |||
func UpdateAllRepoCommitCnt(ctx *macaron.Context) { | |||
repos, err := models.GetAllRepositories() | |||
if err != nil { | |||
log.Error("GetAllRepositories failed:%v", err.Error(), ctx.Data["MsgID"]) | |||
ctx.JSON(http.StatusInternalServerError, map[string]string{ | |||
"error_msg": "GetAllRepositories failed", | |||
}) | |||
return | |||
} | |||
for i, repo := range repos { | |||
log.Info("%d:begin updateRepoCommitCnt(id = %d, name = %s)", i, repo.ID, repo.Name) | |||
if err = updateRepoCommitCnt(ctx, repo); err != nil { | |||
log.Error("updateRepoCommitCnt(id = %d, name = %s) failed:%v", repo.ID, repo.Name, err.Error(), ctx.Data["MsgID"]) | |||
continue | |||
} | |||
log.Info("%d:finish updateRepoCommitCnt(id = %d, name = %s)", i, repo.ID, repo.Name) | |||
} | |||
ctx.JSON(http.StatusOK, map[string]string{ | |||
"error_msg": "", | |||
}) | |||
} |
@@ -546,8 +546,8 @@ func updateRepoCommitCnt(ctx *macaron.Context, repo *models.Repository) error { | |||
} | |||
repo.NumCommit = count | |||
if err = models.UpdateRepositoryCols(repo, "num_commit"); err != nil { | |||
log.Error("UpdateRepositoryCols failed:%v", err.Error(), ctx.Data["MsgID"]) | |||
if err = models.UpdateRepositoryCommitNum(repo); err != nil { | |||
log.Error("UpdateRepositoryCommitNum failed:%v", err.Error(), ctx.Data["MsgID"]) | |||
return err | |||
} | |||
@@ -42,6 +42,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Post("/manager/shutdown", Shutdown) | |||
m.Post("/manager/restart", Restart) | |||
m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues) | |||
m.Post("/cmd/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt) | |||
}, CheckInternalToken) | |||
} |
@@ -39,13 +39,13 @@ | |||
</style> | |||
<div class="ui secondary pointing tabular top attached borderless menu navbar"> | |||
<a class="active item" href="https://git.openi.org.cn/explore/repos?sort=moststars&q=&tab="> | |||
<a class="active item" href="{{$.Link}}?sort=hot&q=&tab="> | |||
<svg class="svg octicon-repo" width="16" height="16" aria-hidden="true"> | |||
<use xlink:href="#octicon-repo" /> | |||
</svg> | |||
热门{{.i18n.Tr "explore.repos"}} | |||
</a> | |||
<a class=" item" href="https://git.openi.org.cn/explore/repos?sort=mostforks&q=&tab="> | |||
<a class=" item" href="{{$.Link}}?sort=active&q=&tab="> | |||
<svg class="svg octicon-inbox" width="16" height="16" aria-hidden="true"> | |||
<use xlink:href="#octicon-inbox" /> | |||
</svg> | |||
@@ -31,10 +31,19 @@ | |||
<!-- Swiper --> | |||
<div class="ui container swiper-container"> | |||
<div class="swiper-wrapper"> | |||
<!--{{range .RecommendOrgs}} | |||
<div class="swiper-slide"> | |||
<div class="ui card"> | |||
<a class="image" href="{{$.HomeLink}}/{{.User.Name}}"> | |||
<img class="ui avatar image" src="{{.User.RelAvatarLink}}" alt="{{.User.Name}}" title="{{.User.Name}}"> | |||
</a> | |||
</div> | |||
</div> | |||
{{end}}--> | |||
<div class="swiper-slide"> | |||
<div class="ui card"> | |||
<a class="image" href="https://git.openi.org.cn/OpenI"> | |||
<img src="/img/org-openi@2x-80.jpg" alt="OpenI" title="OpenI"> | |||
<a class="image" href="https://git.openi.org.cn/user/avatar/OpenI"> | |||
<img src="/img/org-openi@2x-80.jpg" alt="OpenI 启智社区" title="OpenI 启智社区"> | |||
</a> | |||
</div> | |||
</div> | |||