From 9302eba971611601c3ebf6024e22a11c63f4e151 Mon Sep 17 00:00:00 2001 From: zeripath Date: Thu, 23 Sep 2021 16:45:36 +0100 Subject: DBContext is just a Context (#17100) * DBContext is just a Context This PR removes some of the specialness from the DBContext and makes it context This allows us to simplify the GetEngine code to wrap around any context in future and means that we can change our loadRepo(e Engine) functions to simply take contexts. Signed-off-by: Andrew Thornton * fix unit tests Signed-off-by: Andrew Thornton * another place that needs to set the initial context Signed-off-by: Andrew Thornton * avoid race Signed-off-by: Andrew Thornton * change attachment error Signed-off-by: Andrew Thornton --- models/user_follow.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'models/user_follow.go') diff --git a/models/user_follow.go b/models/user_follow.go index ceaaaf9103..8832aa2f18 100644 --- a/models/user_follow.go +++ b/models/user_follow.go @@ -23,7 +23,7 @@ func init() { // IsFollowing returns true if user is following followID. func IsFollowing(userID, followID int64) bool { - has, _ := db.DefaultContext().Engine().Get(&Follow{UserID: userID, FollowID: followID}) + has, _ := db.GetEngine(db.DefaultContext).Get(&Follow{UserID: userID, FollowID: followID}) return has } @@ -33,7 +33,7 @@ func FollowUser(userID, followID int64) (err error) { return nil } - sess := db.DefaultContext().NewSession() + sess := db.NewSession(db.DefaultContext) defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -59,7 +59,7 @@ func UnfollowUser(userID, followID int64) (err error) { return nil } - sess := db.DefaultContext().NewSession() + sess := db.NewSession(db.DefaultContext) defer sess.Close() if err = sess.Begin(); err != nil { return err -- cgit v1.2.3