From ef96edc7af225428b4f9ed750b9aef345297aa61 Mon Sep 17 00:00:00 2001 From: zouap Date: Mon, 7 Mar 2022 10:19:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/models.go | 1 + models/search_record.go | 32 ++++++++++++++++++++++++++++++++ routers/search.go | 4 +++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 models/search_record.go diff --git a/models/models.go b/models/models.go index 0f4679b4f..2d8c0fd05 100755 --- a/models/models.go +++ b/models/models.go @@ -137,6 +137,7 @@ func init() { new(OfficialTag), new(OfficialTagRepos), new(WechatBindLog), + new(SearchRecord), ) tablesStatistic = append(tablesStatistic, diff --git a/models/search_record.go b/models/search_record.go new file mode 100644 index 000000000..391ab164b --- /dev/null +++ b/models/search_record.go @@ -0,0 +1,32 @@ +package models + +import ( + "fmt" + + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/timeutil" +) + +type SearchRecord struct { + ID int64 `xorm:"pk"` + //user + Keyword string `xorm:"NOT NULL"` + // + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` +} + +func SaveSearchKeywordToDb(keyword string) error { + record := &SearchRecord{ + Keyword: keyword, + } + sess := x.NewSession() + defer sess.Close() + + re, err := sess.Insert(record) + if err != nil { + log.Info("insert error." + err.Error()) + return err + } + log.Info("success to save db.re=" + fmt.Sprint((re))) + return nil +} diff --git a/routers/search.go b/routers/search.go index 20663c960..6aeba5082 100644 --- a/routers/search.go +++ b/routers/search.go @@ -52,7 +52,9 @@ func SearchApi(ctx *context.Context) { if PageSize <= 0 || PageSize > 200 { PageSize = setting.UI.IssuePagingNum } - + if Key != "" { + models.SaveSearchKeywordToDb(Key) + } if TableName == "repository" { if OnlySearchLabel { searchRepoByLabel(ctx, Key, Page, PageSize)