Skip to content

Commit

Permalink
perf: 减少题库表字段复杂度, 化繁为简
Browse files Browse the repository at this point in the history
  • Loading branch information
DokiDoki1103 committed Jul 22, 2024
1 parent 51c314c commit 0ccef30
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 73 deletions.
2 changes: 1 addition & 1 deletion cmd/gorm-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
FieldWithIndexTag: true,
FieldWithTypeTag: true,
})
db, _ := gorm.Open(mysql.Open(os.Getenv("DB_DSN")))
db, _ := gorm.Open(mysql.Open(os.Getenv("SQL_DSN")))
g.UseDB(db)

g.ApplyBasic(
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
code.sajari.com/docconv/v2 v2.0.0-pre.3
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/antlabs/strsim v0.0.3
github.com/elastic/go-elasticsearch/v8 v8.11.1
github.com/gin-contrib/static v0.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154Oa
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/advancedlogic/GoOse v0.0.0-20191112112754-e742535969c1 h1:d0Ct1dZwgwMO0Llf81Eu+Lyj6kwqXdqHP/WsSkEria0=
github.com/advancedlogic/GoOse v0.0.0-20191112112754-e742535969c1/go.mod h1:f3HCSN1fBWjcpGtXyM119MJgeQl838v6so/PQOqvE1w=
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=
Expand Down
15 changes: 4 additions & 11 deletions internal/controller/tiku.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ func GetQuestions(c *gin.Context) {
searchValue.Question = util.FormatString(searchValue.Question)
tx := dao.Tiku.Order(dao.Tiku.ID.Desc())
if searchValue.Question != "" {
tx = tx.Where(dao.Tiku.QuestionText.Like("%" + util.GetQuestionText(searchValue.Question) + "%"))
tx = tx.Where(dao.Tiku.Question.Like("%" + searchValue.Question + "%"))
}
if searchValue.Extra != "" {
tx = tx.Where(dao.Tiku.Extra.Like(searchValue.Extra))
}
if searchValue.Source != 0 {
tx = tx.Where(dao.Tiku.Source.Eq(searchValue.Source))
}

if searchValue.OnlyShowEmptyAnswer {
tx = tx.Where(dao.Tiku.Answer.Eq("[]"))
Expand Down Expand Up @@ -125,13 +122,9 @@ func CreateQuestion(c *gin.Context) {
}
var count = 0
for _, tiku := range tikus {
if tiku.Extra != "" {
tiku.Source = 2
} else {
tiku.Source = 1
}
middleware.FillHash(tiku)
err := dao.Tiku.Create(tiku)
t := tiku
middleware.FillHash(t)
err := dao.Tiku.Create(t)
if err == nil {
count++
}
Expand Down
8 changes: 8 additions & 0 deletions internal/dao/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 14 additions & 22 deletions internal/dao/tiku.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ccef30

Please sign in to comment.