Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie Sync: Use max when limit is 0 #4022

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 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 All @@ -29,6 +30,7 @@ import (
"github.com/prebid/prebid-server/v2/stored_requests"
"github.com/prebid/prebid-server/v2/usersync"
"github.com/prebid/prebid-server/v2/util/jsonutil"
"github.com/prebid/prebid-server/v2/util/ptrutil"
stringutil "github.com/prebid/prebid-server/v2/util/stringutil"
"github.com/prebid/prebid-server/v2/util/timeutil"
)
Expand Down Expand Up @@ -181,7 +183,7 @@ func (c *cookieSyncEndpoint) parseRequest(r *http.Request) (usersync.Request, ma
PriorityGroups: c.config.UserSync.PriorityGroups,
},
Debug: request.Debug,
Limit: request.Limit,
Limit: *request.Limit,
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
Privacy: usersyncPrivacy{
gdprPermissions: gdprPerms,
ccpaParsedPolicy: ccpaParsedPolicy,
Expand Down Expand Up @@ -285,17 +287,33 @@ 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 reqLimit == nil && defaultLimit != nil {
limit = defaultLimit
}
if request.Limit < 0 {
request.Limit = 0
if limit == nil || *limit <= 0 || *limit > math.MaxInt32 {
limit = ptrutil.ToPtr(math.MaxInt32)
}
return *limit
}
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

return request
func getEffectiveMaxLimit(maxLimit *int) int {
limit := maxLimit
if maxLimit == nil || *maxLimit <= 0 || *limit > math.MaxInt32 {
limit = ptrutil.ToPtr(math.MaxInt32)
}
return *limit
}
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

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