From 1decd0f4e947f153c867a3d85cbc4e74f9e03ba1 Mon Sep 17 00:00:00 2001 From: Andrey Pozolotin Date: Mon, 15 Jun 2020 14:03:50 +0300 Subject: [PATCH] Fixing --- examples/products/main.go | 19 +++++++++++++++---- pkg/api/common/listing.go | 2 +- pkg/api/products/listing.go | 3 +++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/products/main.go b/examples/products/main.go index 245bf4f..8d91f0a 100644 --- a/examples/products/main.go +++ b/examples/products/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "crypto/tls" "flag" "fmt" "github.com/erply/api-go-wrapper/pkg/api" @@ -18,12 +19,20 @@ func main() { clientCode := flag.String("cc", "", "client code") flag.Parse() + connectionTimeout := 60 * time.Second + transport := &http.Transport{ + DisableKeepAlives: true, + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + ResponseHeaderTimeout: connectionTimeout, + } + httpCl := &http.Client{Transport: transport} + sessionKey, err := auth.VerifyUser(*username, *password, *clientCode, http.DefaultClient) if err != nil { panic(err) } - apiClient, err := api.NewClient(sessionKey, *clientCode, nil) + apiClient, err := api.NewClient(sessionKey, *clientCode, httpCl) if err != nil { panic(err) } @@ -80,8 +89,8 @@ func GetProductsInParallel(cl *api.Client) ([]products.Product, error) { sharedCommon.ListingSettings{ MaxRequestsCountPerSecond: 5, StreamBufferLength: 10, - MaxItemsPerRequest: 10, - MaxFetchersCount: 2, + MaxItemsPerRequest: 300, + MaxFetchersCount: 10, }, productsDataProvider, func(sleepTime time.Duration) { @@ -92,7 +101,9 @@ func GetProductsInParallel(cl *api.Client) ([]products.Product, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second * 5) defer cancel() - prodsChan := lister.Get(ctx, map[string]interface{}{}) + prodsChan := lister.Get(ctx, map[string]interface{}{ + "changedSince": time.Date(2020, 2, 15, 0, 0, 0, 0, time.UTC).Unix(), + }) prods := make([]products.Product, 0) var err error diff --git a/pkg/api/common/listing.go b/pkg/api/common/listing.go index fe9f734..bd04b81 100644 --- a/pkg/api/common/listing.go +++ b/pkg/api/common/listing.go @@ -156,7 +156,7 @@ func (p *Lister) getCursors(ctx context.Context, totalCount int) chan []Cursor { }, ) curPage++ - leftCount -= limit //leftCount 900 + leftCount -= limit } select { case out <- cursorsForBulkRequest: diff --git a/pkg/api/products/listing.go b/pkg/api/products/listing.go index 5edbdc0..29e928c 100644 --- a/pkg/api/products/listing.go +++ b/pkg/api/products/listing.go @@ -15,6 +15,9 @@ func NewListingDataProvider(erplyClient Manager) *ListingDataProvider { } func (l *ListingDataProvider) Count(ctx context.Context, filters map[string]interface{}) (int, error) { + filters["recordsOnPage"] = 1 + filters["pageNo"] = 1 + resp, err := l.erplyAPI.GetProductsBulk(ctx, []map[string]interface{}{filters}, map[string]string{}) if err != nil {