mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Reducing queries
This commit is contained in:
		@@ -54,29 +54,20 @@ func ListActionTasks(ctx *context.APIContext) {
 | 
				
			|||||||
		Status:      actions_model.StatusUnknown, // Unknown means all
 | 
							Status:      actions_model.StatusUnknown, // Unknown means all
 | 
				
			||||||
		IDOrderDesc: true,
 | 
							IDOrderDesc: true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	tasks, err := db.Find[actions_model.ActionTask](ctx, opts)
 | 
					
 | 
				
			||||||
 | 
						tasks, total, err := db.FindAndCount[actions_model.ActionTask](ctx, opts)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
 | 
							ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res := new(api.ActionTaskResponse)
 | 
						res := new(api.ActionTaskResponse)
 | 
				
			||||||
 | 
						res.TotalCount = total
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res.Entries = make([]*api.ActionTask, len(tasks))
 | 
						res.Entries = make([]*api.ActionTask, len(tasks))
 | 
				
			||||||
	for i := range tasks {
 | 
						for i := range tasks {
 | 
				
			||||||
		res.Entries[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i])
 | 
							res.Entries[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i])
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	opts = actions_model.FindTaskOptions{
 | 
					 | 
				
			||||||
		RepoID:      ctx.Repo.Repository.ID,
 | 
					 | 
				
			||||||
		Status:      actions_model.StatusUnknown, // Unknown means all
 | 
					 | 
				
			||||||
		IDOrderDesc: true,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	tasks, res.TotalCount, err = db.FindAndCount[actions_model.ActionTask](ctx, opts)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ctx.JSON(http.StatusOK, &res)
 | 
						ctx.JSON(http.StatusOK, &res)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user