Skip to content

Commit

Permalink
Cookie Sync: Use max when limit is 0 (prebid#4022)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo authored and krdzo committed Oct 30, 2024
1 parent 36a60a8 commit bcc195a
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 87 deletions.
45 changes: 36 additions & 9 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"math"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -174,14 +175,19 @@ 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: request.Limit,
Limit: limit,
Privacy: usersyncPrivacy{
gdprPermissions: gdprPerms,
ccpaParsedPolicy: ccpaParsedPolicy,
Expand Down Expand Up @@ -285,17 +291,38 @@ func (c *cookieSyncEndpoint) writeParseRequestErrorMetrics(err error) {
}

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

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

if limit == nil {
limit = defaultLimit
}
if request.Limit < 0 {
request.Limit = 0

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

return request
return math.MaxInt
}

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

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

return math.MaxInt
}

func (c *cookieSyncEndpoint) setCooperativeSync(request cookieSyncRequest, cookieSyncConfig config.CookieSync) cookieSyncRequest {
Expand Down Expand Up @@ -537,7 +564,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 bcc195a

Please sign in to comment.