Open mdrokz opened 5 months ago
Do it in goroutine try like this func GenerateData() []domain.User{}{ var wg sync.WaitGroup users := []domain.User{} for i := 0; i < 10000; i++ { wg.Add(1) go func(no int) { defer wg.Done()
user := domain.User{}
// err = faker.FakeData(&user)
user.Name = faker.Name()
user.Email = faker.Email()
user.PhoneNumber = faker.Phonenumber()
user.OrganizationID = org.ID
user.Locations = []domain.Location{}
user.Services = []domain.Service{}
_ = faker.FakeData(&user.Locations, options.WithRandomMapAndSliceMinSize(5), options.WithRandomMapAndSliceMaxSize(10))
_ = faker.FakeData(&user.Services, options.WithRandomMapAndSliceMinSize(5), options.WithRandomMapAndSliceMaxSize(10))
if err != nil {
panic(err)
}
users = append(users, user)
}(i + 1)
}
wg.Wait()
return users
} I dont test the code I just thinking about something like this
Interesting. Will need a focus weekend to work on this. I'll pick up and investigate whenever I'm free. But if you have the fixes, please help raise the PR whenever you're ready.
Problem
Hello first of all thanks for the great library! it is really useful
Im using faker to seed my local database and i want to generate 10k elements the issue is if i use fakers default method
faker.FakeData
it hangs & takes up all of my memoryBut if i do it manually like this it finishes in under 1 second
here is the full code & the models
domain.go
main.go