Replace time.Now().Sub with time.Since

This commit is contained in:
shubhendra
2021-02-25 15:58:45 +05:30
parent 512133e14b
commit 644291c028
5 changed files with 6 additions and 18 deletions

View File

@@ -42,7 +42,7 @@ func (mi *MemoryItem) isExpire() bool {
if mi.lifespan == 0 {
return false
}
return time.Now().Sub(mi.createdTime) > mi.lifespan
return time.Since(mi.createdTime) > mi.lifespan
}
// MemoryCache is a memory cache adapter.
@@ -66,7 +66,7 @@ func (bc *MemoryCache) Get(ctx context.Context, key string) (interface{}, error)
bc.RLock()
defer bc.RUnlock()
if itm, ok :=
bc.items[key]; ok {
bc.items[key]; ok {
if itm.isExpire() {
return nil, ErrKeyExpired
}

View File

@@ -85,7 +85,7 @@ func (builder *FilterChainBuilder) report(ctx context.Context, inv *orm.Invocati
}
func (builder *FilterChainBuilder) reportTxn(ctx context.Context, inv *orm.Invocation) {
dur := time.Now().Sub(inv.TxStartTime) / time.Millisecond
dur := time.Since(inv.TxStartTime) / time.Millisecond
summaryVec.WithLabelValues(inv.Method, inv.TxName,
strconv.FormatBool(inv.InsideTx), inv.TxName).Observe(float64(dur))
}

View File

@@ -41,7 +41,7 @@ func NewLog(out io.Writer) *Log {
func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error, args ...interface{}) {
var logMap = make(map[string]interface{})
sub := time.Now().Sub(t) / 1e5
sub := time.Since(t) / 1e5
elsp := float64(int(sub)) / 10.0
logMap["cost_time"] = elsp
flag := " OK"