From b0ebff280626e79eee79cc570db464ecfa036326 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 10 Mar 2022 17:56:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/search_record.go | 14 ++++++++++---- routers/search.go | 24 +++++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/models/search_record.go b/models/search_record.go index 758fbc673..d9408e489 100644 --- a/models/search_record.go +++ b/models/search_record.go @@ -3,6 +3,7 @@ package models import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" + "xorm.io/xorm" ) type SearchRecord struct { @@ -27,18 +28,23 @@ func SaveSearchKeywordToDb(keyword string) error { return nil } -func SearchPrivateIssueOrPr(Page int, PageSize int, Keyword string, isPull bool, userId int64) ([]*Issue, int64, error) { - sess := x.NewSession() - defer sess.Close() - +func setQueryCondition(sess *xorm.Session, Keyword string, isPull bool, userId int64) { sess.And("issue.poster_id=?", userId) sess.And("issue.is_pull=?", isPull) sess.And("(issue.name like '%" + Keyword + "%' or issue.content like '%" + Keyword + "%')") sess.Join("INNER", "repository", "issue.repo_id = repository.id").And("repository.is_private = ?", true) +} + +func SearchPrivateIssueOrPr(Page int, PageSize int, Keyword string, isPull bool, userId int64) ([]*Issue, int64, error) { + sess := x.NewSession() + defer sess.Close() + setQueryCondition(sess, Keyword, isPull, userId) count, err := sess.Count(new(Issue)) if err != nil { return nil, 0, err } + + //setQueryCondition(sess, Keyword, isPull, userId) sess.Desc("issue.created_unix") sess.Limit(PageSize, (Page-1)*PageSize) issues := make([]*Issue, 0) diff --git a/routers/search.go b/routers/search.go index c3a13aef1..646b5b5c8 100644 --- a/routers/search.go +++ b/routers/search.go @@ -145,9 +145,11 @@ func searchRepoByLabel(ctx *context.Context, Key string, Page int, PageSize int) log.Info("not found private repo,keyword=" + Key) } if repos.Len() >= PageSize { - resultObj.Total = int64(WebTotal) - ctx.JSON(200, resultObj) - return + if WebTotal > 0 { + resultObj.Total = int64(WebTotal) + ctx.JSON(200, resultObj) + return + } } } else { if ctx.User == nil { @@ -250,9 +252,11 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa log.Info("not found private repo,keyword=" + Key) } if repos.Len() >= PageSize { - resultObj.Total = int64(WebTotal) - ctx.JSON(200, resultObj) - return + if WebTotal > 0 { + resultObj.Total = int64(WebTotal) + ctx.JSON(200, resultObj) + return + } } } else { if ctx.User == nil { @@ -767,9 +771,11 @@ func searchIssue(ctx *context.Context, TableName string, Key string, Page int, P log.Info("not found private repo issue,keyword=" + Key) } if issuesSize >= PageSize { - resultObj.Total = int64(WebTotal) - ctx.JSON(200, resultObj) - return + if WebTotal > 0 { //next page, not first query. + resultObj.Total = int64(WebTotal) + ctx.JSON(200, resultObj) + return + } } } else { resultObj.PrivateTotal = int64(PrivateTotal)