Skip to content

Commit

Permalink
Do db.Clone() when necessary, remove when it causes bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
violog committed Feb 22, 2024
1 parent 138d7e3 commit d987f1f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/data/pg/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewBalances(db *pgdb.DB) data.BalancesQ {
}

func (q *balances) New() data.BalancesQ {
return NewBalances(q.db.Clone())
return NewBalances(q.db)
}

func (q *balances) Insert(bal data.Balance) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/data/pg/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewEvents(db *pgdb.DB) data.EventsQ {
}

func (q *events) New() data.EventsQ {
return NewEvents(q.db.Clone())
return NewEvents(q.db)
}

func (q *events) Insert(events ...data.Event) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/data/pg/withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewWithdrawals(db *pgdb.DB) data.WithdrawalsQ {
}

func (q *withdrawals) New() data.WithdrawalsQ {
return NewWithdrawals(q.db.Clone())
return NewWithdrawals(q.db)
}

func (q *withdrawals) Insert(w data.Withdrawal) (*data.Withdrawal, error) {
Expand Down
7 changes: 4 additions & 3 deletions internal/service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (

func Run(ctx context.Context, cfg config.Config) {
r := chi.NewRouter()
db := cfg.DB().Clone()

r.Use(
ape.RecoverMiddleware(cfg.Log()),
ape.LoganMiddleware(cfg.Log()),
ape.CtxMiddleware(
handlers.CtxLog(cfg.Log()),
handlers.CtxEventsQ(pg.NewEvents(cfg.DB())),
handlers.CtxBalancesQ(pg.NewBalances(cfg.DB())),
handlers.CtxWithdrawalsQ(pg.NewWithdrawals(cfg.DB())),
handlers.CtxEventsQ(pg.NewEvents(db)),
handlers.CtxBalancesQ(pg.NewBalances(db)),
handlers.CtxWithdrawalsQ(pg.NewWithdrawals(db)),
handlers.CtxEventTypes(cfg.EventTypes()),
handlers.CtxBroadcaster(cfg.Broadcaster()),
handlers.CtxPointPrice(cfg.PointPrice()),
Expand Down
2 changes: 1 addition & 1 deletion internal/service/workers/reopener/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func initialRun(cfg config.Config) error {
var (
q = pg.NewEvents(cfg.DB())
q = pg.NewEvents(cfg.DB().Clone())
log = cfg.Log().WithField("who", "reopener[initializer]")
col = &initCollector{
q: q,
Expand Down
2 changes: 1 addition & 1 deletion internal/service/workers/sbtcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Run(ctx context.Context, cfg extConfig) {

r := &runner{
network: net,
db: cfg.DB(),
db: cfg.DB().Clone(),
types: cfg.EventTypes(),
log: log.WithField("network", name),
cancel: cancel,
Expand Down

0 comments on commit d987f1f

Please sign in to comment.