Skip to content

Commit

Permalink
fix reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Feb 3, 2025
1 parent 28bee0a commit 28ad2e0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion template/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *cacheWithInfo) isNewerThan(key string, t int64) bool {
}

func (c *cacheWithInfo) RecordReplaceTime(time time.Duration) {
c.replaceTime.Add(int64(time))
c.replaceTime.Add(time.Nanoseconds())
}

type (
Expand Down
2 changes: 1 addition & 1 deletion template/cache.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *cacheWithInfo) isNewerThan(key string, t int64) bool {
}

func (c *cacheWithInfo) RecordReplaceTime(time time.Duration) {
c.replaceTime.Add(int64(time))
c.replaceTime.Add(time.Nanoseconds())
}

type (
Expand Down
19 changes: 8 additions & 11 deletions template/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"log"
"strings"
"sync/atomic"
"time"

"github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -53,20 +52,18 @@ func init() {
conditions := query.Select.Conditions
if isSingleUniqueCondition(conditions, query.Select.Table) {
caches[normalized] = &cacheWithInfo{
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: normalized,
info: *query.Select,
uniqueOnly: true,
replaceTime: atomic.Int64{},
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: normalized,
info: *query.Select,
uniqueOnly: true,
}
continue
}
caches[query.Query] = &cacheWithInfo{
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: query.Query,
info: *query.Select,
uniqueOnly: false,
replaceTime: atomic.Int64{},
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: query.Query,
info: *query.Select,
uniqueOnly: false,
}

// TODO: if query is like "SELECT * FROM WHERE pk IN (?, ?, ...)", generate cache with query "SELECT * FROM table WHERE pk = ?"
Expand Down
20 changes: 9 additions & 11 deletions template/driver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,20 @@ func init() {
}

conditions := query.Select.Conditions
if isSingleUniqueCondition(conditions, query.Select.Table) {
if isSingleUniqueCondition(conditions, query.Select.Table) {
caches[normalized] = &cacheWithInfo{
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: normalized,
info: *query.Select,
uniqueOnly: true,
replaceTime: atomic.Int64{},
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: normalized,
info: *query.Select,
uniqueOnly: true,
}
continue
}
caches[query.Query] = &cacheWithInfo{
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: query.Query,
info: *query.Select,
uniqueOnly: false,
replaceTime: atomic.Int64{},
Cache: sc.NewMust(replaceFn, 10*time.Minute, 10*time.Minute),
query: query.Query,
info: *query.Select,
uniqueOnly: false,
}

// TODO: if query is like "SELECT * FROM WHERE pk IN (?, ?, ...)", generate cache with query "SELECT * FROM table WHERE pk = ?"
Expand Down

0 comments on commit 28ad2e0

Please sign in to comment.