Skip to content

Commit

Permalink
Implement TieEjector logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBVolcy committed Aug 15, 2023
1 parent b22b404 commit 8060ba4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion endpoints/setuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func NewSetUIDEndpoint(cfg *config.Configuration, syncersByBidder map[string]use
so.Status = http.StatusBadRequest
return
}
priorityEjector := &usersync.PriorityBidderEjector{PriorityGroups: cfg.UserSync.PriorityGroups}
priorityEjector := &usersync.PriorityBidderEjector{PriorityGroups: cfg.UserSync.PriorityGroups, TieEjector: &usersync.OldestEjector{}}

// Write Cookie
encodedCookie, err := cookie.PrepareCookieForWrite(&cfg.HostCookie, encoder, priorityEjector)
Expand Down
1 change: 1 addition & 0 deletions usersync/cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func TestPrepareCookieForWrite(t *testing.T) {
key: "7",
},
},
TieEjector: &OldestEjector{},
}

testCases := []struct {
Expand Down
6 changes: 3 additions & 3 deletions usersync/ejector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type OldestEjector struct{}
type PriorityBidderEjector struct {
PriorityGroups [][]string
syncersByBidder map[string]Syncer
OldestEjector OldestEjector
TieEjector Ejector
}

// Choose method for oldest ejector will return the oldest uid
Expand All @@ -36,7 +36,7 @@ func (o *OldestEjector) Choose(uids map[string]UIDEntry) (string, error) {
func (p *PriorityBidderEjector) Choose(uids map[string]UIDEntry) (string, error) {
nonPriortyUids := getNonPriorityUids(uids, p.PriorityGroups, p.syncersByBidder)
if len(nonPriortyUids) > 0 {
return p.OldestEjector.Choose(nonPriortyUids)
return p.TieEjector.Choose(nonPriortyUids)
}

lowestPriorityGroup := p.PriorityGroups[len(p.PriorityGroups)-1]
Expand All @@ -48,7 +48,7 @@ func (p *PriorityBidderEjector) Choose(uids map[string]UIDEntry) (string, error)
}

lowestPriorityUids := getPriorityUids(lowestPriorityGroup, uids, p.syncersByBidder)
uidToDelete, err := p.OldestEjector.Choose(lowestPriorityUids)
uidToDelete, err := p.TieEjector.Choose(lowestPriorityUids)
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion usersync/ejector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestPriorityEjector(t *testing.T) {
key: "olderButSamePriority",
},
},
OldestEjector: OldestEjector{},
TieEjector: &OldestEjector{},
},
expected: "olderButSamePriority",
},
Expand Down Expand Up @@ -110,6 +110,7 @@ func TestPriorityEjector(t *testing.T) {
key: "newestNonPriority",
},
},
TieEjector: &OldestEjector{},
},
expected: "oldestNonPriority",
},
Expand Down

0 comments on commit 8060ba4

Please sign in to comment.