Browse Source

增加搜索记录表

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 3 years ago
parent
commit
ef96edc7af
3 changed files with 36 additions and 1 deletions
  1. +1
    -0
      models/models.go
  2. +32
    -0
      models/search_record.go
  3. +3
    -1
      routers/search.go

+ 1
- 0
models/models.go View File

@@ -137,6 +137,7 @@ func init() {
new(OfficialTag),
new(OfficialTagRepos),
new(WechatBindLog),
new(SearchRecord),
)

tablesStatistic = append(tablesStatistic,


+ 32
- 0
models/search_record.go View File

@@ -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
}

+ 3
- 1
routers/search.go View File

@@ -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)


Loading…
Cancel
Save