mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-02-19 00:47:50 -05:00
feat(perf): remove unused size url parameter for local avatars (#10932)
Avatars storage handler ignores the size= url parameter, and we don't have any code for creating multiple sizes of the same avatar. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10932 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
This commit is contained in:
parent
7f22f525fc
commit
10aaef5c7b
4 changed files with 5 additions and 13 deletions
|
|
@ -165,10 +165,7 @@ func GenerateUserAvatarFastLink(userName string, size int) string {
|
|||
}
|
||||
|
||||
// GenerateUserAvatarImageLink returns a link for `User.Avatar` image file: "/avatars/${User.Avatar}"
|
||||
func GenerateUserAvatarImageLink(userAvatar string, size int) string {
|
||||
if size > 0 {
|
||||
return setting.AppSubURL + "/avatars/" + url.PathEscape(userAvatar) + "?size=" + strconv.Itoa(size)
|
||||
}
|
||||
func GenerateUserAvatarImageLink(userAvatar string) string {
|
||||
return setting.AppSubURL + "/avatars/" + url.PathEscape(userAvatar)
|
||||
}
|
||||
|
||||
|
|
@ -210,9 +207,6 @@ func generateEmailAvatarLink(ctx context.Context, email string, size int, final
|
|||
}
|
||||
// for non-final link, we should return fast (use a 302 redirection link)
|
||||
urlStr := setting.AppSubURL + "/avatar/" + url.PathEscape(emailHash)
|
||||
if size > 0 {
|
||||
urlStr += "?size=" + strconv.Itoa(size)
|
||||
}
|
||||
return urlStr
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// AvatarLinkWithSize returns a link to the user's avatar with size. size <= 0 means default size
|
||||
// AvatarLinkWithSize returns a link to the user's avatar. Size is only used for
|
||||
// GenerateEmailAvatarFastLink, for external email-based avatar services
|
||||
func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
|
||||
if u.IsGhost() || u.ID <= 0 {
|
||||
return avatars.DefaultAvatarLink()
|
||||
|
|
@ -88,7 +89,7 @@ func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
|
|||
if u.Avatar == "" {
|
||||
return avatars.DefaultAvatarLink()
|
||||
}
|
||||
return avatars.GenerateUserAvatarImageLink(u.Avatar, size)
|
||||
return avatars.GenerateUserAvatarImageLink(u.Avatar)
|
||||
}
|
||||
return avatars.GenerateEmailAvatarFastLink(ctx, u.AvatarEmail, size)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -13,7 +12,6 @@ import (
|
|||
repo_model "forgejo.org/models/repo"
|
||||
"forgejo.org/models/unittest"
|
||||
"forgejo.org/modules/git"
|
||||
"forgejo.org/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -126,7 +124,7 @@ func TestPushCommits_AvatarLink(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Equal(t,
|
||||
"/avatars/ab53a2911ddf9b4817ac01ddcd3d975f?size="+strconv.Itoa(28*setting.Avatar.RenderedSizeFactor),
|
||||
"/avatars/ab53a2911ddf9b4817ac01ddcd3d975f",
|
||||
pushCommits.AvatarLink(db.DefaultContext, "user2@example.com"))
|
||||
|
||||
assert.Equal(t,
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ func ProfilePost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
// UpdateAvatarSetting update user's avatar
|
||||
// FIXME: limit size.
|
||||
func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *user_model.User) error {
|
||||
ctxUser.UseCustomAvatar = form.Source == forms.AvatarLocal
|
||||
if len(form.Gravatar) > 0 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue