This commit is contained in:
parent
f2c67e33ec
commit
8356a1ec58
|
|
@ -140,15 +140,12 @@ func StartImport(w http.ResponseWriter, route *http.Request) {
|
|||
func importCategoryProducts(dbName string, db *gorm.DB) {
|
||||
defer mainImportWG.Done()
|
||||
|
||||
dbExists := helper.CheckDBExists(os.Getenv("couch_db_source") + dbName)
|
||||
fmt.Println(dbName)
|
||||
|
||||
if dbExists {
|
||||
if dbExists := helper.CheckDBExists(os.Getenv("couch_db_source") + dbName); dbExists {
|
||||
|
||||
totalDocCount := getTotalDocumentCount(dbName)
|
||||
skip := 0
|
||||
limit := 500
|
||||
|
||||
limit := 100
|
||||
totalImport := 0
|
||||
for skip < totalDocCount {
|
||||
|
||||
var response models.BagistoModelResponse
|
||||
|
|
@ -166,20 +163,22 @@ func importCategoryProducts(dbName string, db *gorm.DB) {
|
|||
continue
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &response)
|
||||
|
||||
if err != nil {
|
||||
if err = json.Unmarshal(body, &response); err != nil {
|
||||
log.Println(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
//itearate 100 row products
|
||||
for _, element := range response.Rows {
|
||||
err := ImportProduct(element.Doc, db)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
if err := ImportProduct(element.Doc, db); err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
totalImport++
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("%s total imported documents count %d \n", dbName, totalImport)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(dbName + "+doesnt exist")
|
||||
|
|
@ -247,16 +246,12 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
famAndSellerWG.Wait() //wait until attribute families and sellers are not get from mysql
|
||||
//BEGIN TRANSACTION
|
||||
// begin a transaction
|
||||
|
||||
tx := *db.Begin()
|
||||
categories, keywords, errCat := getCats(&tx, product.Categories)
|
||||
|
||||
categories, keywords, errCat := getCats(&tx, product.Categories)
|
||||
if errCat != nil {
|
||||
log.Println("ERR0001" + errCat.Error())
|
||||
return errCat
|
||||
} else {
|
||||
log.Println(product.Name)
|
||||
}
|
||||
|
||||
brand, err := gm.FindOrCreateBrand(&tx, product.Brand, categories)
|
||||
|
|
@ -657,11 +652,13 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
if errSProduct != nil {
|
||||
log.Println("ERR10" + errSProduct.Error())
|
||||
tx.Rollback()
|
||||
return tx.Rollback().Error
|
||||
return errSProduct
|
||||
} else {
|
||||
log.Println(product.Name)
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func createSellerProduct(flat *gm.ProductFlat, sellerURL string) gm.MarketplaceProduct {
|
||||
|
|
|
|||
Loading…
Reference in New Issue