add cacke
This commit is contained in:
parent
e059a5f64a
commit
345f7c6da4
|
|
@ -47,23 +47,22 @@ func db(data *conf.Data_Database) (*gorm.DB, func()) {
|
||||||
panic("failed to gormDB " + err.Error())
|
panic("failed to gormDB " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
|
|
||||||
//sqlDB.SetMaxIdleConns(int(data.MaxIdle))
|
//sqlDB.SetMaxIdleConns(int(data.MaxIdle))
|
||||||
sqlDB.SetMaxIdleConns(1000)
|
sqlDB.SetMaxIdleConns(1000)
|
||||||
// SetMaxOpenConns sets the maximum number of openapi connections to the database.
|
|
||||||
//sqlDB.SetMaxOpenConns(int(data.MaxOpen))
|
//sqlDB.SetMaxOpenConns(int(data.MaxOpen))
|
||||||
sqlDB.SetMaxOpenConns(3000)
|
sqlDB.SetMaxOpenConns(3000)
|
||||||
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
|
|
||||||
//sqlDB.SetConnMaxLifetime(1 * time.Hour)
|
//sqlDB.SetConnMaxLifetime(1 * time.Hour)
|
||||||
sqlDB.SetConnMaxLifetime(7200 * time.Second)
|
sqlDB.SetConnMaxLifetime(1 * time.Hour)
|
||||||
sqlDB.SetConnMaxIdleTime(15 * time.Minute)
|
sqlDB.SetConnMaxIdleTime(15 * time.Minute)
|
||||||
|
|
||||||
return gormDB, func() {
|
return gormDB, func() {
|
||||||
|
|
||||||
if mysqlConn != nil {
|
if mysqlConn != nil {
|
||||||
fmt.Println("关闭 db")
|
fmt.Println("关闭 db")
|
||||||
if err := mysqlConn.Close(); err != nil {
|
if err := mysqlConn.Close(); err != nil {
|
||||||
fmt.Printf("关闭 db 失败:%v", err)
|
fmt.Printf("关闭 db 失败:%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,10 @@ func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBizNo string) (*bo.OrderBo, error) {
|
func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBizNo string) (*bo.OrderBo, error) {
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, 20*time.Second) // 设置查询超时
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
info := &model.Order{}
|
info := &model.Order{}
|
||||||
|
|
||||||
db := p.DB(ctx)
|
db := p.DB(ctx)
|
||||||
|
|
@ -90,7 +94,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi
|
||||||
|
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
sqlDB, _ := db.DB()
|
sqlDB, _ := db.DB()
|
||||||
log.Warnf("order当前打开连接数: %d,空闲连接数: %d", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
log.Warnf("order当前打开连接数:%d,空闲连接数:%d", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
||||||
|
|
||||||
return nil, fmt.Errorf("order db fail %w", tx.Error)
|
return nil, fmt.Errorf("order db fail %w", tx.Error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ func (r *ProductRepoImpl) getByPNO(ctx context.Context, item *model.Product, PNO
|
||||||
|
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
sqlDB, _ := db.DB()
|
sqlDB, _ := db.DB()
|
||||||
log.Warnf("product当前打开连接数: %d,空闲连接数: %d", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
log.Warnf("product当前打开连接数:%d,空闲连接数:%d", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
||||||
|
|
||||||
return nil, fmt.Errorf("product db fail %w", tx.Error)
|
return nil, fmt.Errorf("product db fail %w", tx.Error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue