mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 19:38:23 +00:00 
			
		
		
		
	Remove NewSession method from db.Engine interface (#17577)
* Remove NewSession method from db.Engine interface * Fix bug * Some improvements * Fix bug * Fix test * Use XXXBean instead of XXXExample
This commit is contained in:
		| @@ -33,24 +33,24 @@ func FollowUser(userID, followID int64) (err error) { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	sess := db.NewSession(db.DefaultContext) | ||||
| 	defer sess.Close() | ||||
| 	if err = sess.Begin(); err != nil { | ||||
| 	ctx, committer, err := db.TxContext() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	defer committer.Close() | ||||
|  | ||||
| 	if err = db.Insert(ctx, &Follow{UserID: userID, FollowID: followID}); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.Insert(&Follow{UserID: userID, FollowID: followID}); err != nil { | ||||
| 	if _, err = db.Exec(ctx, "UPDATE `user` SET num_followers = num_followers + 1 WHERE id = ?", followID); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.Exec("UPDATE `user` SET num_followers = num_followers + 1 WHERE id = ?", followID); err != nil { | ||||
| 	if _, err = db.Exec(ctx, "UPDATE `user` SET num_following = num_following + 1 WHERE id = ?", userID); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.Exec("UPDATE `user` SET num_following = num_following + 1 WHERE id = ?", userID); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return sess.Commit() | ||||
| 	return committer.Commit() | ||||
| } | ||||
|  | ||||
| // UnfollowUser unmarks someone as another's follower. | ||||
| @@ -59,22 +59,22 @@ func UnfollowUser(userID, followID int64) (err error) { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	sess := db.NewSession(db.DefaultContext) | ||||
| 	defer sess.Close() | ||||
| 	if err = sess.Begin(); err != nil { | ||||
| 	ctx, committer, err := db.TxContext() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	defer committer.Close() | ||||
|  | ||||
| 	if _, err = db.DeleteByBean(ctx, &Follow{UserID: userID, FollowID: followID}); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.Delete(&Follow{UserID: userID, FollowID: followID}); err != nil { | ||||
| 	if _, err = db.Exec(ctx, "UPDATE `user` SET num_followers = num_followers - 1 WHERE id = ?", followID); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.Exec("UPDATE `user` SET num_followers = num_followers - 1 WHERE id = ?", followID); err != nil { | ||||
| 	if _, err = db.Exec(ctx, "UPDATE `user` SET num_following = num_following - 1 WHERE id = ?", userID); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.Exec("UPDATE `user` SET num_following = num_following - 1 WHERE id = ?", userID); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return sess.Commit() | ||||
| 	return committer.Commit() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user