Skip to content

Commit

Permalink
fix: time.Since should not be used in defer statement
Browse files Browse the repository at this point in the history
This commit fixes the complaining from `go vet` about the deferring of
`time.Since`. This can cause wrong time evaluation of the elapsed time.
This impact only the debug level, but still it should be addressed.

ref: golang/go#60048

Signed-off-by: Maurizio Del Corno <[email protected]>
  • Loading branch information
druzn3k committed Aug 20, 2024
1 parent c0b6e01 commit f5dbf5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ func (c *immuClient) CurrentState(ctx context.Context) (*schema.ImmutableState,
}

start := time.Now()
defer c.Logger.Debugf("Current state finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("Current state finished in %s", time.Since(start)) }()

return c.ServiceClient.CurrentState(ctx, &empty.Empty{})
}
Expand All @@ -1006,7 +1006,7 @@ func (c *immuClient) Get(ctx context.Context, key []byte, opts ...GetOption) (*s
}

start := time.Now()
defer c.Logger.Debugf("get finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("get finished in %s", time.Since(start)) }()

req := &schema.KeyRequest{Key: key}
for _, opt := range opts {
Expand Down Expand Up @@ -1040,7 +1040,7 @@ func (c *immuClient) GetAtRevision(ctx context.Context, key []byte, rev int64) (
// Gets reads a single value for given key with additional server-provided proof validation.
func (c *immuClient) VerifiedGet(ctx context.Context, key []byte, opts ...GetOption) (vi *schema.Entry, err error) {
start := time.Now()
defer c.Logger.Debugf("VerifiedGet finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("VerifiedGet finished in %s", time.Since(start)) }()

req := &schema.KeyRequest{Key: key}
for _, opt := range opts {
Expand Down Expand Up @@ -1307,7 +1307,7 @@ func (c *immuClient) VerifiedSet(ctx context.Context, key []byte, value []byte)
}

start := time.Now()
defer c.Logger.Debugf("VerifiedSet finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("VerifiedSet finished in %s", time.Since(start)) }()

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down Expand Up @@ -1467,7 +1467,7 @@ func (c *immuClient) GetAll(ctx context.Context, keys [][]byte) (*schema.Entries
}

start := time.Now()
defer c.Logger.Debugf("get-batch finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("get-batch finished in %s", time.Since(start)) }()

keyList := &schema.KeyListRequest{}

Expand Down Expand Up @@ -1495,12 +1495,11 @@ func (c *immuClient) TxByID(ctx context.Context, tx uint64) (*schema.Tx, error)
}

start := time.Now()
defer c.Logger.Debugf("by-index finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("by-index finished in %s", time.Since(start)) }()

t, err := c.ServiceClient.TxById(ctx, &schema.TxRequest{
Tx: tx,
})

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1533,7 +1532,7 @@ func (c *immuClient) VerifiedTxByID(ctx context.Context, tx uint64) (*schema.Tx,
}

start := time.Now()
defer c.Logger.Debugf("VerifiedTxByID finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("VerifiedTxByID finished in %s", time.Since(start)) }()

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down Expand Up @@ -1619,7 +1618,7 @@ func (c *immuClient) History(ctx context.Context, req *schema.HistoryRequest) (s
}

start := time.Now()
defer c.Logger.Debugf("history finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("history finished in %s", time.Since(start)) }()

return c.ServiceClient.History(ctx, req)
}
Expand All @@ -1640,7 +1639,7 @@ func (c *immuClient) SetReferenceAt(ctx context.Context, key []byte, referencedK
}

start := time.Now()
defer c.Logger.Debugf("SetReference finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("SetReference finished in %s", time.Since(start)) }()

txhdr, err := c.ServiceClient.SetReference(ctx, &schema.ReferenceRequest{
Key: key,
Expand Down Expand Up @@ -1683,7 +1682,7 @@ func (c *immuClient) VerifiedSetReferenceAt(ctx context.Context, key []byte, ref
}

start := time.Now()
defer c.Logger.Debugf("safereference finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("safereference finished in %s", time.Since(start)) }()

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down Expand Up @@ -1798,7 +1797,7 @@ func (c *immuClient) ZAddAt(ctx context.Context, set []byte, score float64, key
}

start := time.Now()
defer c.Logger.Debugf("zadd finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("zadd finished in %s", time.Since(start)) }()

hdr, err := c.ServiceClient.ZAdd(ctx, &schema.ZAddRequest{
Set: set,
Expand Down Expand Up @@ -1848,7 +1847,7 @@ func (c *immuClient) VerifiedZAddAt(ctx context.Context, set []byte, score float
}

start := time.Now()
defer c.Logger.Debugf("safezadd finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("safezadd finished in %s", time.Since(start)) }()

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *immuClient) _streamVerifiedSet(ctx context.Context, kvs []*stream.KeyVa
defer c.StateService.CacheUnlock()

start := time.Now()
defer c.Logger.Debugf("StreamVerifiedSet finished in %s", time.Since(start))
defer func() { c.Logger.Debugf("StreamVerifiedSet finished in %s", time.Since(start)) }()

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down

0 comments on commit f5dbf5b

Please sign in to comment.