Skip to content

Commit

Permalink
chore: removed unused buried at field
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww committed May 23, 2023
1 parent d43d416 commit 420ddc9
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 22 deletions.
6 changes: 2 additions & 4 deletions capsule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
)

type TimeCapsule[P any] struct {
Payload P `json:"payload"`
BuriedAt int64 `json:"buriedAt"`
DugOutAt int64 `json:"dugOutAt"`

Payload P `json:"payload"`
DugOutAt int64 `json:"-"`
base64Str string
}

Expand Down
5 changes: 1 addition & 4 deletions capsule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"encoding/json"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -15,9 +14,7 @@ func TestNewTimeCapsuleFromBase64String(t *testing.T) {
require := require.New(t)

capsule := TimeCapsule[string]{
Payload: "hello",
BuriedAt: time.Now().UnixMilli(),
DugOutAt: time.Now().UnixMilli(),
Payload: "hello",
}

jsonData, err := json.Marshal(capsule)
Expand Down
4 changes: 1 addition & 3 deletions dataloader_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ func (r *RedisDataloader[P]) BuryFor(ctx context.Context, payload P, forTimeRang
//
// ZADD sortedSetKey utilUnixMilliTimestamp <capsule base64 string>
func (r *RedisDataloader[P]) BuryUtil(ctx context.Context, payload P, utilUnixMilliTimestamp int64) error {
now := time.Now().UTC().UnixMilli()
newCapsule := TimeCapsule[any]{Payload: payload, BuriedAt: now}

newCapsule := TimeCapsule[any]{Payload: payload}
return r.bury(ctx, newCapsule.Base64String(), utilUnixMilliTimestamp)
}

Expand Down
4 changes: 0 additions & 4 deletions dataloader_redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestRedisDataloader(t *testing.T) {
now := time.Now().UTC()
assert.GreaterOrEqual(now.Add(time.Minute).UnixMilli(), int64(mems[0].Score))
assert.Equal("test", capsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), capsule.BuriedAt)
})

t.Run("BuryUtil", func(t *testing.T) {
Expand Down Expand Up @@ -101,7 +100,6 @@ func TestRedisDataloader(t *testing.T) {
now := time.Now().UTC()
assert.GreaterOrEqual(now.Add(time.Hour).UnixMilli(), int64(mems[0].Score))
assert.Equal("test", capsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), capsule.BuriedAt)
})

t.Run("Dig", func(t *testing.T) {
Expand Down Expand Up @@ -131,7 +129,6 @@ func TestRedisDataloader(t *testing.T) {

now := time.Now().UTC()
assert.Equal("shouldBeDugOut", capsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), capsule.BuriedAt)
assert.GreaterOrEqual(now.UnixMilli(), capsule.DugOutAt)
})

Expand Down Expand Up @@ -169,7 +166,6 @@ func TestRedisDataloader(t *testing.T) {

now := time.Now().UTC()
assert.Equal("shouldNotBeDugOut", requeuedCapsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), requeuedCapsule.BuriedAt)
assert.GreaterOrEqual(now.UnixMilli(), requeuedCapsule.DugOutAt)
})
})
Expand Down
4 changes: 1 addition & 3 deletions dataloader_rueidis.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ func (r *RueidisDataloader[P]) BuryFor(ctx context.Context, payload P, forTimeRa
//
// ZADD sortedSetKey utilUnixMilliTimestamp <capsule base64 string>
func (r *RueidisDataloader[P]) BuryUtil(ctx context.Context, payload P, utilUnixMilliTimestamp int64) error {
now := time.Now().UTC().UnixMilli()
newCapsule := TimeCapsule[any]{Payload: payload, BuriedAt: now}

newCapsule := TimeCapsule[any]{Payload: payload}
return r.bury(ctx, newCapsule.Base64String(), utilUnixMilliTimestamp)
}

Expand Down
4 changes: 0 additions & 4 deletions dataloader_rueidis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func TestRueidisDataloder(t *testing.T) {
now := time.Now().UTC()
assert.GreaterOrEqual(now.Add(time.Minute).UnixMilli(), int64(mems[0].Score))
assert.Equal("test", capsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), capsule.BuriedAt)
})

t.Run("BuryUtil", func(t *testing.T) {
Expand Down Expand Up @@ -118,7 +117,6 @@ func TestRueidisDataloder(t *testing.T) {
now := time.Now().UTC()
assert.GreaterOrEqual(now.Add(time.Hour).UnixMilli(), int64(mems[0].Score))
assert.Equal("test", capsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), capsule.BuriedAt)
})

t.Run("Dig", func(t *testing.T) {
Expand Down Expand Up @@ -147,7 +145,6 @@ func TestRueidisDataloder(t *testing.T) {

now := time.Now().UTC()
assert.Equal("shouldBeDugOut", capsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), capsule.BuriedAt)
assert.GreaterOrEqual(now.UnixMilli(), capsule.DugOutAt)
})

Expand Down Expand Up @@ -192,7 +189,6 @@ func TestRueidisDataloder(t *testing.T) {

now := time.Now().UTC()
assert.Equal("shouldNotBeDugOut", requeuedCapsule.Payload)
assert.GreaterOrEqual(now.UnixMilli(), requeuedCapsule.BuriedAt)
assert.GreaterOrEqual(now.UnixMilli(), requeuedCapsule.DugOutAt)
})
})
Expand Down

0 comments on commit 420ddc9

Please sign in to comment.