Merge pull request #292 from ClusterCockpit/hotfix

Hotfix: add orderBy param to jobRepo.Find
This commit is contained in:
Christoph Kluge 2024-10-31 15:51:32 +01:00 committed by GitHub
commit ae53e87aba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 1 deletions

View File

@ -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 {

View File

@ -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())
} }

View File

@ -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)
} }

View File

@ -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)