fix connections leak (#4826)
* fix connections leak * fix connections leak * fix connections leak * fix connections leak Co-authored-by: 李龙 <lilong.21@bytedance.com>
This commit is contained in:
		
							parent
							
								
									7b927900e9
								
							
						
					
					
						commit
						c170af11e9
					
				| @ -5,7 +5,7 @@ import ( | ||||
| ) | ||||
| 
 | ||||
| func BeginTransaction(db *gorm.DB) { | ||||
| 	if !db.Config.SkipDefaultTransaction { | ||||
| 	if !db.Config.SkipDefaultTransaction && db.Error == nil { | ||||
| 		if tx := db.Begin(); tx.Error == nil { | ||||
| 			db.Statement.ConnPool = tx.Statement.ConnPool | ||||
| 			db.InstanceSet("gorm:started_transaction", true) | ||||
|  | ||||
| @ -285,8 +285,8 @@ func (db *DB) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *DB) { | ||||
| 	queryTx := db.Limit(1).Order(clause.OrderByColumn{ | ||||
| 		Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey}, | ||||
| 	}) | ||||
| 
 | ||||
| 	if tx = queryTx.Find(dest, conds...); queryTx.RowsAffected == 0 { | ||||
| 	if tx = queryTx.Find(dest, conds...); tx.Error == nil { | ||||
| 		if tx.RowsAffected == 0 { | ||||
| 			if c, ok := tx.Statement.Clauses["WHERE"]; ok { | ||||
| 				if where, ok := c.Expression.(clause.Where); ok { | ||||
| 					tx.assignInterfacesToValue(where.Exprs) | ||||
| @ -321,8 +321,8 @@ func (db *DB) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *DB) { | ||||
| 
 | ||||
| 			return tx.Model(dest).Updates(assigns) | ||||
| 		} | ||||
| 
 | ||||
| 	return db | ||||
| 	} | ||||
| 	return tx | ||||
| } | ||||
| 
 | ||||
| // Update update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 kinggo
						kinggo