Skip to content

Commit 25e409e

Browse files
GiteaBotlunny
andauthored
Return default avatar url when user id is zero rather than updating database (go-gitea#34094) (go-gitea#34095)
Backport go-gitea#34094 by @lunny When visit commit list, it would update the user avatar even if id = 0, which was unnecessary operations. This PR returned default avatar for the git only user avatar rendering who's user id is zero. ```log database duration=0.0005s db.sql="UPDATE `user` SET `avatar` = ?, `updated_unix` = ? WHERE `id`=?" database duration=0.0007s db.sql="UPDATE `user` SET `avatar` = ?, `updated_unix` = ? WHERE `id`=?" ... ``` Co-authored-by: Lunny Xiao <[email protected]>
1 parent f8f24d8 commit 25e409e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

models/user/avatar.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
6161

6262
// AvatarLinkWithSize returns a link to the user's avatar with size. size <= 0 means default size
6363
func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
64-
if u.IsGhost() || u.IsGiteaActions() {
64+
// ghost user was deleted, Gitea actions is a bot user, 0 means the user should be a virtual user
65+
// which comes from git configure information
66+
if u.IsGhost() || u.IsGiteaActions() || u.ID <= 0 {
6567
return avatars.DefaultAvatarLink()
6668
}
6769

0 commit comments

Comments
 (0)