Performance improvement for users page

This commit is contained in:
Eduard Urbach 2017-11-18 11:28:53 +01:00
parent 16c76670e8
commit bd293de4be
4 changed files with 35 additions and 2 deletions

21
pages/company/company.go Normal file
View File

@ -0,0 +1,21 @@
package company
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
// Get company.
func Get(ctx *aero.Context) string {
id := ctx.Get("id")
company, err := arn.GetCompany(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Company not found", err)
}
return ctx.HTML(components.CompanyPage(company))
}

View File

@ -0,0 +1,2 @@
component CompanyPage(company *arn.Company)
h1= company.Name.English

View File

@ -13,6 +13,7 @@ import (
"github.com/animenotifier/notify.moe/pages/apiview"
"github.com/animenotifier/notify.moe/pages/character"
"github.com/animenotifier/notify.moe/pages/charge"
"github.com/animenotifier/notify.moe/pages/company"
"github.com/animenotifier/notify.moe/pages/compare"
"github.com/animenotifier/notify.moe/pages/database"
"github.com/animenotifier/notify.moe/pages/editanime"
@ -92,6 +93,9 @@ func Configure(app *aero.Application) {
// Characters
l.Page("/character/:id", character.Get)
// Companies
l.Page("/company/:id", company.Get)
// Settings
l.Page("/settings", settings.Get(components.SettingsPersonal))
l.Page("/settings/accounts", settings.Get(components.SettingsAccounts))

View File

@ -14,9 +14,15 @@ func Active(ctx *aero.Context) string {
return user.IsActive() && user.HasAvatar()
})
followCount := map[*arn.User]int{}
for _, user := range users {
followCount[user] = user.FollowersCount()
}
sort.Slice(users, func(i, j int) bool {
followersA := users[i].FollowersCount()
followersB := users[j].FollowersCount()
followersA := followCount[users[i]]
followersB := followCount[users[j]]
if followersA == followersB {
return users[i].Nick < users[j].Nick