diff --git a/fortnite/person.go b/fortnite/person.go index 2ab6fa3..cad9720 100644 --- a/fortnite/person.go +++ b/fortnite/person.go @@ -6,6 +6,7 @@ import ( "github.com/ectrc/snow/aid" p "github.com/ectrc/snow/person" + "github.com/ectrc/snow/storage" ) var ( @@ -115,15 +116,7 @@ func NewFortnitePerson(displayName string, everything bool) *p.Person { person.AthenaProfile.Attributes.AddAttribute(p.NewAttribute("active_loadout_index", 0)).Save() if everything { - for _, item := range Cosmetics.Items { - if strings.Contains(strings.ToLower(item.ID), "random") { - continue - } - - item := p.NewItem(item.Type.BackendValue + ":" + item.ID, 1) - item.HasSeen = true - person.AthenaProfile.Items.AddItem(item).Save() - } + GiveEverything(person) } person.Save() @@ -132,13 +125,24 @@ func NewFortnitePerson(displayName string, everything bool) *p.Person { } func GiveEverything(person *p.Person) { + items := make([]storage.DB_Item, 0) + for _, item := range Cosmetics.Items { if strings.Contains(strings.ToLower(item.ID), "random") { continue } + has := person.AthenaProfile.Items.GetItemByTemplateID(item.ID) + if has != nil { + continue + } + item := p.NewItem(item.Type.BackendValue + ":" + item.ID, 1) item.HasSeen = true - person.AthenaProfile.Items.AddItem(item).Save() + person.AthenaProfile.Items.AddItem(item) + + items = append(items, *item.ToDatabase(person.AthenaProfile.ID)) } + + storage.Repo.BulkCreateItems(&items) } \ No newline at end of file diff --git a/person/item.go b/person/item.go index e1697b5..36a0f3a 100644 --- a/person/item.go +++ b/person/item.go @@ -172,8 +172,8 @@ func (i *Item) ToDatabase(profileId string) *storage.DB_Item { } return &storage.DB_Item{ - ProfileID: profileId, ID: i.ID, + ProfileID: profileId, TemplateID: i.TemplateID, Quantity: i.Quantity, Favorite: i.Favorite, diff --git a/storage/postgres.go b/storage/postgres.go index d5771db..8a4efe9 100644 --- a/storage/postgres.go +++ b/storage/postgres.go @@ -171,6 +171,10 @@ func (s *PostgresStorage) SaveItem(item *DB_Item) { s.Postgres.Save(item) } +func (s *PostgresStorage) BulkCreateItems(items *[]DB_Item) { + s.Postgres.Create(items) +} + func (s *PostgresStorage) DeleteItem(itemId string) { s.Postgres.Delete(&DB_Item{}, "id = ?", itemId) } diff --git a/storage/storage.go b/storage/storage.go index 4e92828..52af0e2 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -22,6 +22,7 @@ type Storage interface { DeleteProfile(profileId string) SaveItem(item *DB_Item) + BulkCreateItems(items *[]DB_Item) DeleteItem(itemId string) SaveVariant(variant *DB_VariantChannel) @@ -118,6 +119,10 @@ func (r *Repository) SaveItem(item *DB_Item) { r.Storage.SaveItem(item) } +func (r *Repository) BulkCreateItems(items *[]DB_Item) { + r.Storage.BulkCreateItems(items) +} + func (r *Repository) DeleteItem(itemId string) { r.Storage.DeleteItem(itemId) } diff --git a/storage/tables.go b/storage/tables.go index d97f381..a7447a3 100644 --- a/storage/tables.go +++ b/storage/tables.go @@ -171,7 +171,7 @@ type DB_SeasonStat struct { XP int Tier int Stars int - LevelClainmed int + LevelClaimed int TierClaimed int }