feat: refactor product attributes caching logic and add HashArray utility function
This commit is contained in:
@@ -199,27 +199,7 @@ func (a *apiRepository) StreamProductAttributesCache(ctx context.Context, market
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
identifider, err := mp.GetIdentifier()
|
||||
if err != nil {
|
||||
errChan <- fmt.Errorf("getting marketplace identifier: %w", err)
|
||||
return
|
||||
}
|
||||
key := fmt.Sprintf("ozon:products:attributes:%s", identifider)
|
||||
var cachedMessage pb.GetProductAttributesResponse
|
||||
err = redis.ReadProtoMessage(ctx, key, &cachedMessage)
|
||||
if err == nil && len(cachedMessage.Items) > 0 {
|
||||
resultChan <- utils.DerefSlice(cachedMessage.Items)
|
||||
return
|
||||
}
|
||||
converter := generated.ConverterImpl{}
|
||||
var allAttributes []PbProductAttributes
|
||||
defer func() {
|
||||
if len(allAttributes) == 0 {
|
||||
return
|
||||
}
|
||||
message := pb.GetProductAttributesResponse{Items: utils.ToPtrs(allAttributes)}
|
||||
_ = redis.WriteProtoMessage(ctx, key, &message)
|
||||
}()
|
||||
|
||||
for _, chunk := range lo.Chunk(productIds, 1000) {
|
||||
chunkStrings := lo.Map(chunk, func(item int, index int) string {
|
||||
@@ -241,10 +221,7 @@ func (a *apiRepository) StreamProductAttributesCache(ctx context.Context, market
|
||||
return *converter.AttributesToProto(&item)
|
||||
})
|
||||
resultChan <- attrs
|
||||
allAttributes = append(allAttributes, attrs...)
|
||||
|
||||
}
|
||||
//ozonClient.Products().GetDescriptionOfProducts()
|
||||
}
|
||||
|
||||
func (a *apiRepository) DeleteProducts(ctx context.Context, marketplaceId int, items []*PbDeleteProductRequestItem) ([]*PbDeleteProductResponseItem, error) {
|
||||
|
||||
Reference in New Issue
Block a user