Don't case extra allocations. Revert 70s state wait for ttl deletion

Signed-off-by: joshvanl <me@joshvanl.dev>
This commit is contained in:
joshvanl 2023-02-17 17:44:53 +00:00
parent 974d2acd4e
commit db56a28581
2 changed files with 11 additions and 12 deletions

View File

@ -222,16 +222,15 @@ func (m *MongoDB) setInternal(ctx context.Context, req *state.SetRequest) error
return err
}
update := mongo.Pipeline{
bson.D{{Key: "$set", Value: bson.D{
{Key: id, Value: req.Key},
{Key: value, Value: v},
{Key: etag, Value: etagV.String()},
}}},
}
update := make(mongo.Pipeline, 2)
update[0] = bson.D{{Key: "$set", Value: bson.D{
{Key: id, Value: req.Key},
{Key: value, Value: v},
{Key: etag, Value: etagV.String()},
}}}
if reqTTL != nil {
update = append(update, primitive.D{{Key: "$addFields", Value: bson.D{
update[1] = primitive.D{{Key: "$addFields", Value: bson.D{
{Key: daprttl, Value: bson.D{
{Key: "$dateAdd", Value: bson.D{
{Key: "startDate", Value: "$$NOW"},
@ -239,12 +238,12 @@ func (m *MongoDB) setInternal(ctx context.Context, req *state.SetRequest) error
{Key: "amount", Value: *reqTTL}},
},
}},
}}})
}}}
} else {
update = append(update, primitive.D{
update[1] = primitive.D{
{Key: "$addFields", Value: bson.D{
{Key: daprttl, Value: nil},
}}})
}}}
}
_, err = m.collection.UpdateOne(ctx, filter, update, options.Update().SetUpsert(true))

View File

@ -807,7 +807,7 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
})
require.NoError(t, err)
return res.Data == nil
}, time.Second*70, 200*time.Millisecond, "expected object to have been deleted in time")
}, time.Second*3, 200*time.Millisecond, "expected object to have been deleted in time")
})
}
}