fix(kv): Move timestamp updating to kv put functions

pull/14742/head
Jade McGough 2019-08-21 22:20:02 -07:00
parent 360a393c5e
commit 85d4c323a9
4 changed files with 14 additions and 12 deletions

View File

@ -28,6 +28,14 @@ func (log *CRUDLog) SetUpdatedAt(now time.Time) {
log.UpdatedAt = now
}
// UpdateTimestamps always sets UpdatedAt to now. If CreatedAt is unset, it will set it to now.
func (log *CRUDLog) UpdateTimestamps(now time.Time) {
log.UpdatedAt = now
if log.CreatedAt.IsZero() {
log.CreatedAt = now
}
}
// TimeGenerator represents a generator for now.
type TimeGenerator interface {
// Now creates the generated time.

View File

@ -383,9 +383,6 @@ func (s *Service) createBucket(ctx context.Context, tx Tx, b *influxdb.Bucket) e
}
b.ID = s.IDGenerator.ID()
now := s.Now()
b.CreatedAt = now
b.UpdatedAt = now
if err := s.appendBucketEventToLog(ctx, tx, b.ID, bucketCreatedEvent); err != nil {
return &influxdb.Error{
@ -446,6 +443,8 @@ func (s *Service) createBucketUserResourceMappings(ctx context.Context, tx Tx, b
}
func (s *Service) putBucket(ctx context.Context, tx Tx, b *influxdb.Bucket) error {
b.UpdateTimestamps(s.Now())
span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish()

View File

@ -249,9 +249,6 @@ func (s *Service) createOrganization(ctx context.Context, tx Tx, o *influxdb.Org
}
o.ID = s.IDGenerator.ID()
now := s.Now()
o.CreatedAt = now
o.UpdatedAt = now
if err := s.appendOrganizationEventToLog(ctx, tx, o.ID, organizationCreatedEvent); err != nil {
return &influxdb.Error{
Err: err,
@ -278,6 +275,8 @@ func (s *Service) PutOrganization(ctx context.Context, o *influxdb.Organization)
}
func (s *Service) putOrganization(ctx context.Context, tx Tx, o *influxdb.Organization) error {
o.UpdateTimestamps(s.Now())
v, err := json.Marshal(o)
if err != nil {
return &influxdb.Error{
@ -405,8 +404,6 @@ func (s *Service) updateOrganization(ctx context.Context, tx Tx, id influxdb.ID,
o.Description = *upd.Description
}
o.UpdatedAt = s.Now()
if err := s.appendOrganizationEventToLog(ctx, tx, o.ID, organizationUpdatedEvent); err != nil {
return nil, &influxdb.Error{
Err: err,

View File

@ -242,9 +242,6 @@ func (s *Service) CreateVariable(ctx context.Context, variable *influxdb.Variabl
if err := s.putVariableOrgsIndex(ctx, tx, variable); err != nil {
return err
}
now := s.Now()
variable.CreatedAt = now
variable.UpdatedAt = now
if pe := s.putVariable(ctx, tx, variable); pe != nil {
return &influxdb.Error{
Err: pe,
@ -330,6 +327,8 @@ func (s *Service) removeVariableOrgsIndex(ctx context.Context, tx Tx, variable *
}
func (s *Service) putVariable(ctx context.Context, tx Tx, variable *influxdb.Variable) error {
variable.UpdateTimestamps(s.Now())
m, err := json.Marshal(variable)
if err != nil {
return &influxdb.Error{
@ -369,7 +368,6 @@ func (s *Service) UpdateVariable(ctx context.Context, id influxdb.ID, update *in
Err: pe,
}
}
m.UpdatedAt = s.Now()
if err := update.Apply(m); err != nil {
return &influxdb.Error{
Err: err,