aboutsummaryrefslogtreecommitdiffstats
path: root/models/user/follow.go
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-09-16 16:39:12 +0200
committerGitHub <noreply@github.com>2023-09-16 14:39:12 +0000
commitf91dbbba98c841f11d99be998ed5dd98122a457c (patch)
tree9c6c935ccf745c5a1716f1330922354809cd39e0 /models/user/follow.go
parenta1b2a118123e0abd1d4737f4a6c0cf56d15eff57 (diff)
downloadgitea-f91dbbba98c841f11d99be998ed5dd98122a457c.tar.gz
gitea-f91dbbba98c841f11d99be998ed5dd98122a457c.zip
Next round of `db.DefaultContext` refactor (#27089)
Part of #27065
Diffstat (limited to 'models/user/follow.go')
-rw-r--r--models/user/follow.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/models/user/follow.go b/models/user/follow.go
index 7efecc26a7..f4dd2891ff 100644
--- a/models/user/follow.go
+++ b/models/user/follow.go
@@ -4,6 +4,8 @@
package user
import (
+ "context"
+
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
)
@@ -21,18 +23,18 @@ func init() {
}
// IsFollowing returns true if user is following followID.
-func IsFollowing(userID, followID int64) bool {
- has, _ := db.GetEngine(db.DefaultContext).Get(&Follow{UserID: userID, FollowID: followID})
+func IsFollowing(ctx context.Context, userID, followID int64) bool {
+ has, _ := db.GetEngine(ctx).Get(&Follow{UserID: userID, FollowID: followID})
return has
}
// FollowUser marks someone be another's follower.
-func FollowUser(userID, followID int64) (err error) {
- if userID == followID || IsFollowing(userID, followID) {
+func FollowUser(ctx context.Context, userID, followID int64) (err error) {
+ if userID == followID || IsFollowing(ctx, userID, followID) {
return nil
}
- ctx, committer, err := db.TxContext(db.DefaultContext)
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -53,12 +55,12 @@ func FollowUser(userID, followID int64) (err error) {
}
// UnfollowUser unmarks someone as another's follower.
-func UnfollowUser(userID, followID int64) (err error) {
- if userID == followID || !IsFollowing(userID, followID) {
+func UnfollowUser(ctx context.Context, userID, followID int64) (err error) {
+ if userID == followID || !IsFollowing(ctx, userID, followID) {
return nil
}
- ctx, committer, err := db.TxContext(db.DefaultContext)
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}