From 22f275fb03d00ba0ff5e14936e63f0f9e3755352 Mon Sep 17 00:00:00 2001 From: merdan Date: Wed, 3 May 2023 14:56:23 +0500 Subject: [PATCH] fix sql --- bagisto_models/product.go | 4 ++-- main.go | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bagisto_models/product.go b/bagisto_models/product.go index 6dcc907..7a842d2 100644 --- a/bagisto_models/product.go +++ b/bagisto_models/product.go @@ -140,8 +140,8 @@ func GetWishlistProducts(db *gorm.DB) ([]Product, error) { func GetFlatSources(db *gorm.DB) ([]ProductAttributeValue, error) { var productSources []ProductAttributeValue err := db.Joins("JOIN wishlist wp ON product_attribute_values.product_id = wp.product_id"). - Joins("JOIN marketplace_products mp ON product_attribute_values.product_id = mp.product_id where marketplace_seller_id=1"). - Find(&productSources, "text_value IS NOT NULL AND attribute_id=31").Error + Joins("JOIN marketplace_products mp ON product_attribute_values.product_id = mp.product_id"). + Find(&productSources, "mp.marketplace_seller_id=1 AND product_attribute_values.text_value IS NOT NULL AND product_attribute_values.attribute_id=31").Error if err != nil { log.Println(err.Error()) diff --git a/main.go b/main.go index 96fc1f7..a9216e5 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,6 @@ func main() { if err != nil { log.Fatalf("Error connecting to database: %s", err) } - importer, _ := repositories.ParseImporterInstance(db) updatePeriodStr := os.Getenv("UPDATE_PERIOD") updatePeriod, err := time.ParseDuration(updatePeriodStr) @@ -49,7 +48,7 @@ func main() { } // Start the worker stopCh := make(chan struct{}) - go worker(importer, stopCh, updatePeriod) + go worker(db, stopCh, updatePeriod) // Wait for termination signal signalCh := make(chan os.Signal, 1) @@ -70,10 +69,13 @@ func main() { } } -func worker(importer *repositories.Importer, stopCh <-chan struct{}, updatePeriod time.Duration) { - ticker := time.NewTicker(updatePeriod) +func worker(db *gorm.DB, stopCh <-chan struct{}, updatePeriod time.Duration) { + importer, _ := repositories.ParseImporterInstance(db) + ticker := time.NewTicker(time.Second) + ticker = time.NewTicker(updatePeriod) defer ticker.Stop() log.Printf("Updater worker Started") + for { select { case <-stopCh: @@ -85,7 +87,7 @@ func worker(importer *repositories.Importer, stopCh <-chan struct{}, updatePerio log.Println("Error retrieving products:", err) continue } else { - log.Println(len(result)) + log.Println(result) } // Update products as needed