Skip to content

Commit

Permalink
Revert "Cookie Sync: Use max when limit is 0 (prebid#4022)"
Browse files Browse the repository at this point in the history
This reverts commit bcc195a.
  • Loading branch information
krdzo authored Oct 30, 2024
1 parent bcc195a commit 4d2313f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 216 deletions.
45 changes: 9 additions & 36 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"math"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -175,19 +174,14 @@ func (c *cookieSyncEndpoint) parseRequest(r *http.Request) (usersync.Request, ma
tcf2Cfg := c.privacyConfig.tcf2ConfigBuilder(c.privacyConfig.gdprConfig.TCF2, account.GDPR)
gdprPerms := c.privacyConfig.gdprPermissionsBuilder(tcf2Cfg, gdprRequestInfo)

limit := math.MaxInt
if request.Limit != nil {
limit = *request.Limit
}

rx := usersync.Request{
Bidders: request.Bidders,
Cooperative: usersync.Cooperative{
Enabled: (request.CooperativeSync != nil && *request.CooperativeSync) || (request.CooperativeSync == nil && c.config.UserSync.Cooperative.EnabledByDefault),
PriorityGroups: c.config.UserSync.PriorityGroups,
},
Debug: request.Debug,
Limit: limit,
Limit: request.Limit,
Privacy: usersyncPrivacy{
gdprPermissions: gdprPerms,
ccpaParsedPolicy: ccpaParsedPolicy,
Expand Down Expand Up @@ -291,38 +285,17 @@ func (c *cookieSyncEndpoint) writeParseRequestErrorMetrics(err error) {
}

func (c *cookieSyncEndpoint) setLimit(request cookieSyncRequest, cookieSyncConfig config.CookieSync) cookieSyncRequest {
limit := getEffectiveLimit(request.Limit, cookieSyncConfig.DefaultLimit)
maxLimit := getEffectiveMaxLimit(cookieSyncConfig.MaxLimit)
if maxLimit < limit {
request.Limit = &maxLimit
} else {
request.Limit = &limit
if request.Limit <= 0 && cookieSyncConfig.DefaultLimit != nil {
request.Limit = *cookieSyncConfig.DefaultLimit
}
return request
}

func getEffectiveLimit(reqLimit *int, defaultLimit *int) int {
limit := reqLimit

if limit == nil {
limit = defaultLimit
if cookieSyncConfig.MaxLimit != nil && (request.Limit <= 0 || request.Limit > *cookieSyncConfig.MaxLimit) {
request.Limit = *cookieSyncConfig.MaxLimit
}

if limit != nil && *limit > 0 {
return *limit
if request.Limit < 0 {
request.Limit = 0
}

return math.MaxInt
}

func getEffectiveMaxLimit(maxLimit *int) int {
limit := maxLimit

if limit != nil && *limit > 0 {
return *limit
}

return math.MaxInt
return request
}

func (c *cookieSyncEndpoint) setCooperativeSync(request cookieSyncRequest, cookieSyncConfig config.CookieSync) cookieSyncRequest {
Expand Down Expand Up @@ -564,7 +537,7 @@ type cookieSyncRequest struct {
GDPR *int `json:"gdpr"`
GDPRConsent string `json:"gdpr_consent"`
USPrivacy string `json:"us_privacy"`
Limit *int `json:"limit"`
Limit int `json:"limit"`
GPP string `json:"gpp"`
GPPSID string `json:"gpp_sid"`
CooperativeSync *bool `json:"coopSync"`
Expand Down
Loading

0 comments on commit 4d2313f

Please sign in to comment.