fix: unblock first growth report generation
This commit is contained in:
@@ -37,9 +37,15 @@ func (s *Service) Create(ctx context.Context, userID, merchantID int64, request
|
||||
return Record{}, false, ErrDisabled
|
||||
}
|
||||
now := s.now().UTC()
|
||||
if err := s.coordinator.AllowCreate(ctx, userID, now); err != nil {
|
||||
hasAISummary, err := s.repository.HasAISummary(ctx, merchantID, request.TerminalID, growth.AnalyticsVersion)
|
||||
if err != nil {
|
||||
return Record{}, false, err
|
||||
}
|
||||
if hasAISummary {
|
||||
if err := s.coordinator.AllowCreate(ctx, userID, now); err != nil {
|
||||
return Record{}, false, err
|
||||
}
|
||||
}
|
||||
watermark, start, err := s.repository.DatasetMetadata(ctx)
|
||||
if err != nil {
|
||||
return Record{}, false, err
|
||||
@@ -51,11 +57,14 @@ func (s *Service) Create(ctx context.Context, userID, merchantID int64, request
|
||||
refreshDay = &day
|
||||
}
|
||||
record, cached, err := s.repository.CreateOrReuse(ctx, CreateRecord{ID: newReportID(), MerchantID: merchantID, TerminalID: request.TerminalID, Fingerprint: fingerprint, DatasetWatermark: watermark, ForecastStartDate: &start, CatalogVersion: growth.CatalogVersion, AnalyticsVersion: growth.AnalyticsVersion, PromptVersion: s.config.PromptVersion, SchemaVersion: s.config.SchemaVersion, Model: s.config.Model, ManualRefresh: request.Refresh, RefreshDay: refreshDay, IdempotencyKey: idempotencyKey, RequestHash: RequestHash(merchantID, request.TerminalID, request.Refresh)}, func() error {
|
||||
return s.coordinator.AllowUncached(ctx, merchantID, now)
|
||||
if !hasAISummary {
|
||||
return nil
|
||||
}
|
||||
return s.coordinator.AllowUncached(ctx, merchantID, request.TerminalID, now)
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrRefreshLimited) {
|
||||
next, quotaErr := s.repository.NextRefreshAt(ctx, merchantID, request.TerminalID, now)
|
||||
next, quotaErr := s.repository.NextRefreshAt(ctx, merchantID, request.TerminalID, growth.AnalyticsVersion, now)
|
||||
if quotaErr != nil {
|
||||
return Record{}, false, quotaErr
|
||||
}
|
||||
@@ -64,7 +73,7 @@ func (s *Service) Create(ctx context.Context, userID, merchantID int64, request
|
||||
return Record{}, false, err
|
||||
}
|
||||
record.Cached = cached
|
||||
record.NextRefreshAt, err = s.repository.NextRefreshAt(ctx, merchantID, request.TerminalID, now)
|
||||
record.NextRefreshAt, err = s.repository.NextRefreshAt(ctx, merchantID, request.TerminalID, growth.AnalyticsVersion, now)
|
||||
return record, cached, err
|
||||
}
|
||||
func (s *Service) Get(ctx context.Context, merchantID int64, id string) (Record, error) {
|
||||
@@ -74,7 +83,7 @@ func (s *Service) Get(ctx context.Context, merchantID int64, id string) (Record,
|
||||
if record.Scope.TerminalID != nil {
|
||||
terminalID = *record.Scope.TerminalID
|
||||
}
|
||||
record.NextRefreshAt, _ = s.repository.NextRefreshAt(ctx, merchantID, terminalID, s.now())
|
||||
record.NextRefreshAt, _ = s.repository.NextRefreshAt(ctx, merchantID, terminalID, growth.AnalyticsVersion, s.now())
|
||||
}
|
||||
return record, err
|
||||
}
|
||||
@@ -88,7 +97,7 @@ func (s *Service) Latest(ctx context.Context, merchantID int64, terminalID strin
|
||||
} else {
|
||||
record.Stale = record.Fingerprint != s.fingerprint(merchantID, terminalID, watermark, start)
|
||||
}
|
||||
record.NextRefreshAt, _ = s.repository.NextRefreshAt(ctx, merchantID, terminalID, s.now())
|
||||
record.NextRefreshAt, _ = s.repository.NextRefreshAt(ctx, merchantID, terminalID, growth.AnalyticsVersion, s.now())
|
||||
}
|
||||
return record, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user