Skip to content

Commit

Permalink
Merge pull request #292 from ClusterCockpit/hotfix
Browse files Browse the repository at this point in the history
Hotfix: add orderBy param to jobRepo.Find
  • Loading branch information
spacehamster87 authored Oct 31, 2024
2 parents 8a0e6c9 + 939dd23 commit ae53e87
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/api/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ func (api *RestApi) stopJobByRequest(rw http.ResponseWriter, r *http.Request) {
return
}

// log.Printf("loading db job for stopJobByRequest... : stopJobApiRequest=%v", req)
job, err = api.JobRepository.Find(req.JobId, req.Cluster, req.StartTime)

if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/repository/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func (r *JobRepository) Find(
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))
return scanJob(q.RunWith(r.stmtCache).QueryRow())
}
Expand Down
3 changes: 2 additions & 1 deletion internal/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,10 @@ const ContextUserKey ContextKey = "user"
func GetUserFromContext(ctx context.Context) *schema.User {
x := ctx.Value(ContextUserKey)
if x == nil {
log.Warnf("no user retrieved from context")
return nil
}

// log.Infof("user retrieved from context: %v", x.(*schema.User))
return x.(*schema.User)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/routerConfig/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ func setupHomeRoute(i InfoType, r *http.Request) InfoType {
jobRepo := repository.GetJobRepository()
groupBy := model.AggregateCluster

// startJobCount := time.Now()
stats, err := jobRepo.JobCountGrouped(r.Context(), nil, &groupBy)
if err != nil {
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")
if err != nil {
log.Warnf("failed to count running jobs: %s", err.Error())
}
// log.Infof("Timer HOME ROUTE startRunningJobCount: %s", time.Since(startRunningJobCount))

i["clusters"] = stats

Expand Down Expand Up @@ -268,6 +272,7 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {

// Get User -> What if NIL?
user := repository.GetUserFromContext(r.Context())

// Get Roles
availableRoles, _ := schema.GetValidRolesMap(user)

Expand Down

0 comments on commit ae53e87

Please sign in to comment.