diff --git a/internal/api/rest.go b/internal/api/rest.go index f143a7f..5f8e15c 100644 --- a/internal/api/rest.go +++ b/internal/api/rest.go @@ -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 { diff --git a/internal/repository/job.go b/internal/repository/job.go index b42598d..84b13a0 100644 --- a/internal/repository/job.go +++ b/internal/repository/job.go @@ -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()) } diff --git a/internal/repository/user.go b/internal/repository/user.go index 3b7d945..19364dc 100644 --- a/internal/repository/user.go +++ b/internal/repository/user.go @@ -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) } diff --git a/internal/routerConfig/routes.go b/internal/routerConfig/routes.go index 1dd6dee..e7dc924 100644 --- a/internal/routerConfig/routes.go +++ b/internal/routerConfig/routes.go @@ -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 @@ -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)