Commit 928a987b authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

optimize SQL query

parent cc651198
......@@ -136,11 +136,7 @@ func (d *Dao) IsTaskDone(tid int, userId string) (ok bool, err error) {
return count > 0, err
}
func (d *Dao) GetTaskResult(tid int, userId string) (status string, submittedAt time.Time, err error) {
isDailyTask, err := d.IsDailyTask(tid)
if err != nil {
return "", time.Time{}, err
}
func (d *Dao) GetTaskResult(isDailyTask bool, tid int, userId string) (status string, submittedAt time.Time, err error) {
temp := &dbModel.TaskHistory{}
tx := d.db.Session(&gorm.Session{Logger: logger.Default.LogMode(logger.Silent)})
if !isDailyTask {
......
......@@ -79,7 +79,18 @@ func checkTask(c *gin.Context) {
return
}
status, _, err := srv.GetTaskResult(taskId, userId)
task, err := srv.GetTaskDetail(taskId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
}
if task == nil {
c.JSON(200, withError("task not found"))
return
}
status, _, err := srv.GetTaskResult(task.Daily, taskId, userId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
......@@ -116,8 +127,7 @@ func submitTask(c *gin.Context) {
c.JSON(200, withError("task not found"))
return
}
status, _, err := srv.GetTaskResult(taskId, userId)
status, _, err := srv.GetTaskResult(task.Daily, taskId, userId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
......
......@@ -74,7 +74,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
Enable: task.Enable,
}
status, submittedAt, err := s.GetTaskResult(_task.TaskId.(int), userId)
status, submittedAt, err := s.GetTaskResult(_task.Daily, _task.TaskId.(int), userId)
if err != nil {
log.WithError(err).Error("group check task")
return nil, err
......
......@@ -149,8 +149,8 @@ func (s *Service) GetTaskDetail(taskId int) (task *dbModel.Task, err error) {
return
}
func (s *Service) GetTaskResult(taskId int, userId string) (status string, submittedAt time.Time, err error) {
status, submittedAt, err = s.d.GetTaskResult(taskId, userId)
func (s *Service) GetTaskResult(isDailyTask bool, taskId int, userId string) (status string, submittedAt time.Time, err error) {
status, submittedAt, err = s.d.GetTaskResult(isDailyTask, taskId, userId)
if err != nil {
log.WithError(err).Error("get task result error")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment