mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 13:29:05 +01:00
Merge pull request #292 from ClusterCockpit/hotfix
Hotfix: add orderBy param to jobRepo.Find
This commit is contained in:
commit
ae53e87aba
@ -929,6 +929,7 @@ func (api *RestApi) stopJobByRequest(rw http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log.Printf("loading db job for stopJobByRequest... : stopJobApiRequest=%v", req)
|
||||||
job, err = api.JobRepository.Find(req.JobId, req.Cluster, req.StartTime)
|
job, err = api.JobRepository.Find(req.JobId, req.Cluster, req.StartTime)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -235,6 +235,11 @@ func (r *JobRepository) Find(
|
|||||||
q = q.Where("job.start_time = ?", *startTime)
|
q = q.Where("job.start_time = ?", *startTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q = q.OrderBy("job.id DESC") // always use newest matching job by db id if more than one match
|
||||||
|
|
||||||
|
// s, args, _ := q.ToSql()
|
||||||
|
// log.Printf("trying to find db job with query: %s | %v", s, args)
|
||||||
|
|
||||||
log.Debugf("Timer Find %s", time.Since(start))
|
log.Debugf("Timer Find %s", time.Since(start))
|
||||||
return scanJob(q.RunWith(r.stmtCache).QueryRow())
|
return scanJob(q.RunWith(r.stmtCache).QueryRow())
|
||||||
}
|
}
|
||||||
|
@ -321,9 +321,10 @@ const ContextUserKey ContextKey = "user"
|
|||||||
func GetUserFromContext(ctx context.Context) *schema.User {
|
func GetUserFromContext(ctx context.Context) *schema.User {
|
||||||
x := ctx.Value(ContextUserKey)
|
x := ctx.Value(ContextUserKey)
|
||||||
if x == nil {
|
if x == nil {
|
||||||
|
log.Warnf("no user retrieved from context")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// log.Infof("user retrieved from context: %v", x.(*schema.User))
|
||||||
return x.(*schema.User)
|
return x.(*schema.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,15 +51,19 @@ func setupHomeRoute(i InfoType, r *http.Request) InfoType {
|
|||||||
jobRepo := repository.GetJobRepository()
|
jobRepo := repository.GetJobRepository()
|
||||||
groupBy := model.AggregateCluster
|
groupBy := model.AggregateCluster
|
||||||
|
|
||||||
|
// startJobCount := time.Now()
|
||||||
stats, err := jobRepo.JobCountGrouped(r.Context(), nil, &groupBy)
|
stats, err := jobRepo.JobCountGrouped(r.Context(), nil, &groupBy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to count jobs: %s", err.Error())
|
log.Warnf("failed to count jobs: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
// log.Infof("Timer HOME ROUTE startJobCount: %s", time.Since(startJobCount))
|
||||||
|
|
||||||
|
// startRunningJobCount := time.Now()
|
||||||
stats, err = jobRepo.AddJobCountGrouped(r.Context(), nil, &groupBy, stats, "running")
|
stats, err = jobRepo.AddJobCountGrouped(r.Context(), nil, &groupBy, stats, "running")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to count running jobs: %s", err.Error())
|
log.Warnf("failed to count running jobs: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
// log.Infof("Timer HOME ROUTE startRunningJobCount: %s", time.Since(startRunningJobCount))
|
||||||
|
|
||||||
i["clusters"] = stats
|
i["clusters"] = stats
|
||||||
|
|
||||||
@ -268,6 +272,7 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
|
|||||||
|
|
||||||
// Get User -> What if NIL?
|
// Get User -> What if NIL?
|
||||||
user := repository.GetUserFromContext(r.Context())
|
user := repository.GetUserFromContext(r.Context())
|
||||||
|
|
||||||
// Get Roles
|
// Get Roles
|
||||||
availableRoles, _ := schema.GetValidRolesMap(user)
|
availableRoles, _ := schema.GetValidRolesMap(user)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user