Better Output!
This commit is contained in:
parent
7ca1c05520
commit
2e8d2fbc95
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
func FiberLogger() fiber.Handler {
|
||||
return logger.New(logger.Config{
|
||||
Format: "${status} ${path}\n",
|
||||
Format: "(${status}) (${latency}) ${path}\n",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
10
aid/print.go
10
aid/print.go
|
@ -27,13 +27,15 @@ func PrintJSON(v interface{}) {
|
|||
}
|
||||
|
||||
func PrintTime(label string, functions ...func()) {
|
||||
current := time.Now()
|
||||
|
||||
for _, f := range functions {
|
||||
f()
|
||||
}
|
||||
|
||||
if Config.Output.Level == "prod" {
|
||||
return
|
||||
}
|
||||
|
||||
current := time.Now()
|
||||
for _, f := range functions {
|
||||
f()
|
||||
}
|
||||
fmt.Println(label + ":", time.Since(current))
|
||||
}
|
|
@ -25,7 +25,6 @@ func PostProfileAction(c *fiber.Ctx) error {
|
|||
if person == nil {
|
||||
return c.Status(404).JSON(aid.ErrorBadRequest("No Account Found"))
|
||||
}
|
||||
defer person.Save()
|
||||
|
||||
profile := person.GetProfileFromType(c.Query("profileId"))
|
||||
defer profile.ClearProfileChanges()
|
||||
|
@ -79,7 +78,7 @@ func PostMarkItemSeenAction(c *fiber.Ctx, person *p.Person, profile *p.Profile)
|
|||
}
|
||||
|
||||
item.HasSeen = true
|
||||
item.Save()
|
||||
go item.Save()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -106,6 +105,9 @@ func PostEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, pr
|
|||
if attr == nil {
|
||||
return c.Status(400).JSON(aid.ErrorBadRequest("Attribute not found"))
|
||||
}
|
||||
defer func() {
|
||||
go attr.Save()
|
||||
}()
|
||||
|
||||
switch body.SlotName {
|
||||
case "Dance":
|
||||
|
@ -120,7 +122,5 @@ func PostEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, pr
|
|||
attr.ValueJSON = aid.JSONStringify(item.ID)
|
||||
}
|
||||
|
||||
attr.Save()
|
||||
|
||||
return nil
|
||||
}
|
6
main.go
6
main.go
|
@ -46,6 +46,12 @@ func init() {
|
|||
aid.Print("Loaded person: " + person.DisplayName)
|
||||
}
|
||||
})
|
||||
|
||||
aid.PrintTime("Loading all persons from cache", func() {
|
||||
for _, person := range person.AllFromCache() {
|
||||
aid.Print("Loaded person: " + person.DisplayName)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package person
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -45,7 +44,6 @@ func (m *PersonsCache) CacheKiller() {
|
|||
|
||||
func (m *PersonsCache) GetPerson(id string) *Person {
|
||||
if p, ok := m.Load(id); ok {
|
||||
fmt.Println("Cache hit", id)
|
||||
cacheEntry := p.(*CacheEntry)
|
||||
return cacheEntry.Entry
|
||||
}
|
||||
|
|
|
@ -118,7 +118,6 @@ func findHelper(databasePerson *storage.DB_Person) *Person {
|
|||
|
||||
func AllFromDatabase() []*Person {
|
||||
var persons []*Person
|
||||
|
||||
for _, person := range storage.Repo.GetAllPersons() {
|
||||
persons = append(persons, Find(person.ID))
|
||||
}
|
||||
|
@ -126,6 +125,20 @@ func AllFromDatabase() []*Person {
|
|||
return persons
|
||||
}
|
||||
|
||||
func AllFromCache() []*Person {
|
||||
if cache == nil {
|
||||
cache = NewPersonsCacheMutex()
|
||||
}
|
||||
|
||||
var persons []*Person
|
||||
cache.RangeEntry(func(key string, value *CacheEntry) bool {
|
||||
persons = append(persons, value.Entry)
|
||||
return true
|
||||
})
|
||||
|
||||
return persons
|
||||
}
|
||||
|
||||
func (p *Person) GetProfileFromType(profileType string) *Profile {
|
||||
switch profileType {
|
||||
case "athena":
|
||||
|
|
Loading…
Reference in New Issue
Block a user