cache and stats
This commit is contained in:
@ -895,6 +895,11 @@ func parseEwayDumpAction(ctx context.Context, cmd *cli.Command) error {
|
||||
}
|
||||
|
||||
itemsUpdated := make(map[string]struct{}, len(seenItems))
|
||||
stats := struct {
|
||||
fetchedInfo int
|
||||
handledAll int
|
||||
cachedInfo int
|
||||
}{}
|
||||
|
||||
startFrom := time.Now()
|
||||
for {
|
||||
@ -928,14 +933,17 @@ func parseEwayDumpAction(ctx context.Context, cmd *cli.Command) error {
|
||||
goodsItems = goodsItems[:0]
|
||||
for _, item := range items {
|
||||
var pi entity.GoodsItemInfo
|
||||
if seenItem, ok := seenItems[item.SKU]; ok {
|
||||
seenItem := seenItems[item.SKU]
|
||||
if len(seenItem.Parameters) != 0 && len(seenItem.PhotoURLs) != 0 {
|
||||
pi.Parameters = seenItem.Parameters
|
||||
pi.PhotoURLs = seenItem.PhotoURLs
|
||||
stats.cachedInfo++
|
||||
} else {
|
||||
pi, err = client.GetProductInfo(ctx, int64(item.Cart))
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting product info: %w", err)
|
||||
}
|
||||
stats.fetchedInfo++
|
||||
}
|
||||
|
||||
goodsItem, err := entity.MakeGoodsItem(item, remnants, pi)
|
||||
@ -945,6 +953,7 @@ func parseEwayDumpAction(ctx context.Context, cmd *cli.Command) error {
|
||||
}
|
||||
|
||||
itemsUpdated[goodsItem.Articul] = struct{}{}
|
||||
stats.handledAll++
|
||||
|
||||
goodsItems = append(goodsItems, goodsItem)
|
||||
if goodsItem.Type == "" {
|
||||
@ -1001,8 +1010,22 @@ func parseEwayDumpAction(ctx context.Context, cmd *cli.Command) error {
|
||||
for k := range itemsUpdated {
|
||||
delete(seenItems, k)
|
||||
}
|
||||
|
||||
logger.Info().
|
||||
Int("handled", stats.handledAll).
|
||||
Int("cached", stats.cachedInfo).
|
||||
Int("fetched", stats.fetchedInfo).
|
||||
Int("to_delete", len(seenItems)).
|
||||
Msg("processed items")
|
||||
|
||||
for k := range seenItems {
|
||||
repository.GoodsItem().Delete(ctx, k)
|
||||
out, err := repository.GoodsItem().Delete(ctx, k)
|
||||
if err != nil {
|
||||
logger.Warn().Err(err).Str("sku", k).Msg("unable to delete item")
|
||||
continue
|
||||
}
|
||||
|
||||
logger.Debug().Str("sku", k).Msg("deleted item")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user