Skip to content

Commit

Permalink
feat: reviewed/unreviewed filter
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Aug 28, 2023
1 parent 862e780 commit 3cbe5a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 2 additions & 4 deletions internal/controller/poll/poll_v1_get_polls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package poll
import (
"context"

"github.com/gogf/gf/v2/frame/g"

"github.com/hitokoto-osc/reviewer/internal/model"

"github.com/hitokoto-osc/reviewer/internal/consts"
Expand All @@ -24,8 +22,8 @@ func (c *ControllerV1) GetPolls(ctx context.Context, req *v1.GetPollsReq) (res *
if user.Role != consts.UserRoleAdmin && req.StatusEnd >= int(consts.PollStatusApproved) {
return nil, gerror.NewCode(gcode.CodeInvalidOperation, "权限不足")
}
keys, e := g.DB().GetCache().KeyStrings(ctx)
g.Log().Debugf(ctx, "%+v %+v", keys, e)
// keys, e := g.DB().GetCache().KeyStrings(ctx)
// g.Log().Debugf(ctx, "%+v %+v", keys, e)
out, err := service.Poll().GetPollList(ctx, &model.GetPollListInput{
StatusStart: req.StatusStart,
StatusEnd: req.StatusEnd,
Expand Down
18 changes: 9 additions & 9 deletions internal/logic/poll/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,15 @@ WHERE
} else {
query = query.WhereBetween(dao.Poll.Columns().Status, in.StatusStart, in.StatusEnd)
}
query = query.Order(dao.Poll.Columns().CreatedAt, in.Order).
Page(in.Page, in.PageSize)
eg, egCtx := errgroup.WithContext(ctx)
query.Ctx(egCtx)
eg.Go(func() error {
var e error
q := query.Clone()
count, e = q.Count()
g.Log().Debugf(ctx, "count: %d", count)
return e
})
eg.Go(func() error {
q := query.Clone()
if in.WithCache {
Expand Down Expand Up @@ -192,13 +198,7 @@ WHERE
Force: false,
})
}
e := q.Scan(&result)
return e
})
eg.Go(func() error {
var e error
q := query.Clone()
count, e = q.Count()
e := q.Order(dao.Poll.Columns().CreatedAt, in.Order).Page(in.Page, in.PageSize).Scan(&result)
return e
})
if err := eg.Wait(); err != nil {
Expand Down

0 comments on commit 3cbe5a9

Please sign in to comment.