diff --git a/server/service/osquery.go b/server/service/osquery.go index d989db8c18..3d0c34bd81 100644 --- a/server/service/osquery.go +++ b/server/service/osquery.go @@ -807,6 +807,10 @@ func (svc *Service) disablePoliciesDuringSetupExperience(ctx context.Context, ho // It returns (nil, true, nil) if the interval is so that policies should be executed on the host, but there are no policies // assigned to such host. func (svc *Service) policyQueriesForHost(ctx context.Context, host *fleet.Host) (policyQueries map[string]string, noPoliciesForHost bool, err error) { + policyReportedAt := svc.task.GetHostPolicyReportedAt(ctx, host) + if !svc.shouldUpdate(policyReportedAt, svc.config.Osquery.PolicyUpdateInterval, host.ID) && !host.RefetchRequested { + return nil, false, nil + } disablePolicies, err := svc.disablePoliciesDuringSetupExperience(ctx, host) if err != nil { return nil, false, ctxerr.Wrap(ctx, err, "check if host is in setup experience") @@ -815,10 +819,6 @@ func (svc *Service) policyQueriesForHost(ctx context.Context, host *fleet.Host) level.Debug(svc.logger).Log("msg", "skipping policy queries for host in setup experience", "host_id", host.ID) return nil, false, nil } - policyReportedAt := svc.task.GetHostPolicyReportedAt(ctx, host) - if !svc.shouldUpdate(policyReportedAt, svc.config.Osquery.PolicyUpdateInterval, host.ID) && !host.RefetchRequested { - return nil, false, nil - } policyQueries, err = svc.ds.PolicyQueriesForHost(ctx, host) if err != nil { return nil, false, ctxerr.Wrap(ctx, err, "retrieve policy queries")