diff --git a/controllers/importer.go b/controllers/importer.go index a7087c0..8a6899c 100644 --- a/controllers/importer.go +++ b/controllers/importer.go @@ -101,7 +101,12 @@ func Start(w http.ResponseWriter, route *http.Request) { } mainImportWG.Wait() + err = gm.Flush() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } elapsed := time.Since(start) log.Printf("end import took %s", elapsed) @@ -117,7 +122,7 @@ func startImport(dbName string, db *gorm.DB) { totalDocCount := getTotalDocumentCount(dbName) skip := 0 - limit := 100 + limit := 500 for skip < totalDocCount { @@ -195,7 +200,6 @@ func getCats(db *gorm.DB, catIDs []int) ([]gm.Category, string, error) { keywords += "," + translation.MetaKeywords } - } return categories, keywords, nil diff --git a/gorm_models/product.go b/gorm_models/product.go index 6c1ffd9..85f28f5 100644 --- a/gorm_models/product.go +++ b/gorm_models/product.go @@ -1,7 +1,9 @@ package gorm_models import ( + helper "db_service/pkg" "gorm.io/gorm" + "os" "time" ) @@ -96,3 +98,9 @@ func DeleteProducts(db *gorm.DB) error { return db.Exec("DELETE p.* FROM products p, order_items oi,wishlist f WHERE oi.product_id != p.id AND oi.parent_id != p.id AND f.product_id != p.id").Error } + +func Flush() error { + _, err := helper.SendRequest("GET", os.Getenv("couch_db_source"), nil, "", true) + + return err +}