diff --git a/aid/fiber.go b/aid/fiber.go index 024413f..8ed811d 100644 --- a/aid/fiber.go +++ b/aid/fiber.go @@ -10,7 +10,7 @@ import ( func FiberLogger() fiber.Handler { return logger.New(logger.Config{ - Format: "${status} ${path}\n", + Format: "(${status}) (${latency}) ${path}\n", }) } diff --git a/aid/print.go b/aid/print.go index c6fbcd3..4e1f5f1 100644 --- a/aid/print.go +++ b/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)) } \ No newline at end of file diff --git a/handlers/profile.go b/handlers/profile.go index 19d0901..520927d 100644 --- a/handlers/profile.go +++ b/handlers/profile.go @@ -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 } \ No newline at end of file diff --git a/main.go b/main.go index 47ddf99..16ff15c 100644 --- a/main.go +++ b/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() { diff --git a/person/cache.go b/person/cache.go index 097b872..4fe9b5c 100644 --- a/person/cache.go +++ b/person/cache.go @@ -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 } diff --git a/person/person.go b/person/person.go index 1b859ef..e19c771 100644 --- a/person/person.go +++ b/person/person.go @@ -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": diff --git a/readme.md b/readme.md index 825746b..33ea1a0 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ # Snow -Performance first, universal Fortnite backend written in Go. +Performance first, universal Fortnite private server backend written in Go. ## Features