feat: implement HashArray utility and refactor product key generation for Redis

This commit is contained in:
2025-08-17 11:46:44 +03:00
parent e35d44dacb
commit fb1be5ddc3
6 changed files with 40 additions and 14 deletions

View File

@@ -39,6 +39,10 @@ func NewAPIRepository(marketplaceRepository marketplace.Repository) Repository {
}
}
func GetProductKey(identifier string) string {
return fmt.Sprintf("ym:products:%s", identifier)
}
// getBusinessID retrieves the business ID for a given marketplace by looking up the campaign
func (r *apiRepository) getBusinessID(ctx context.Context, mp *marketplace.Marketplace) (int64, error) {
if mp.CampaignID == "" {
@@ -101,7 +105,7 @@ func (r *apiRepository) GetProducts(ctx context.Context, marketplaceID int, req
errChan <- err
return
}
key := fmt.Sprintf("ym:products:%d", businessID)
key := GetProductKey(strconv.Itoa(int(businessID)))
var cachedMessage pb.GetProductsResponse
err = redis.ReadProtoMessage(ctx, key, &cachedMessage)
if err == nil && len(cachedMessage.Offers) > 0 {