@@ -98,6 +98,8 @@ import {defer, GreedyPromise} from './utils/promise.js';
98
98
import { useMetrics } from './utils/perfMetrics.js' ;
99
99
import { adjustCpm } from './utils/cpm.js' ;
100
100
import { getGlobal } from './prebidGlobal.js' ;
101
+ import { ttlCollection } from './utils/ttlCollection.js' ;
102
+ import { getMinBidCacheTTL , onMinBidCacheTTLChange } from './bidTTL.js' ;
101
103
102
104
const { syncUsers } = userSync ;
103
105
@@ -153,7 +155,10 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
153
155
let _bidsRejected = [ ] ;
154
156
let _callback = callback ;
155
157
let _bidderRequests = [ ] ;
156
- let _bidsReceived = [ ] ;
158
+ let _bidsReceived = ttlCollection ( {
159
+ startTime : ( bid ) => bid . responseTimestamp ,
160
+ ttl : ( bid ) => getMinBidCacheTTL ( ) == null ? null : Math . max ( getMinBidCacheTTL ( ) , bid . ttl ) * 1000
161
+ } ) ;
157
162
let _noBids = [ ] ;
158
163
let _winningBids = [ ] ;
159
164
let _auctionStart ;
@@ -162,8 +167,10 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
162
167
let _auctionStatus ;
163
168
let _nonBids = [ ] ;
164
169
170
+ onMinBidCacheTTLChange ( ( ) => _bidsReceived . refresh ( ) ) ;
171
+
165
172
function addBidRequests ( bidderRequests ) { _bidderRequests = _bidderRequests . concat ( bidderRequests ) ; }
166
- function addBidReceived ( bidsReceived ) { _bidsReceived = _bidsReceived . concat ( bidsReceived ) ; }
173
+ function addBidReceived ( bid ) { _bidsReceived . add ( bid ) ; }
167
174
function addBidRejected ( bidsRejected ) { _bidsRejected = _bidsRejected . concat ( bidsRejected ) ; }
168
175
function addNoBid ( noBid ) { _noBids = _noBids . concat ( noBid ) ; }
169
176
function addNonBids ( seatnonbids ) { _nonBids = _nonBids . concat ( seatnonbids ) ; }
@@ -179,7 +186,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
179
186
labels : _labels ,
180
187
bidderRequests : _bidderRequests ,
181
188
noBids : _noBids ,
182
- bidsReceived : _bidsReceived ,
189
+ bidsReceived : _bidsReceived . toArray ( ) ,
183
190
bidsRejected : _bidsRejected ,
184
191
winningBids : _winningBids ,
185
192
timeout : _timeout ,
@@ -219,7 +226,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
219
226
bidsBackCallback ( _adUnits , function ( ) {
220
227
try {
221
228
if ( _callback != null ) {
222
- const bids = _bidsReceived
229
+ const bids = _bidsReceived . toArray ( )
223
230
. filter ( bid => _adUnitCodes . includes ( bid . adUnitCode ) )
224
231
. reduce ( groupByPlacement , { } ) ;
225
232
_callback . apply ( pbjsInstance , [ bids , timedOut , _auctionId ] ) ;
@@ -246,7 +253,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
246
253
function auctionDone ( ) {
247
254
config . resetBidder ( ) ;
248
255
// when all bidders have called done callback atleast once it means auction is complete
249
- logInfo ( `Bids Received for Auction with id: ${ _auctionId } ` , _bidsReceived ) ;
256
+ logInfo ( `Bids Received for Auction with id: ${ _auctionId } ` , _bidsReceived . toArray ( ) ) ;
250
257
_auctionStatus = AUCTION_COMPLETED ;
251
258
executeCallback ( false ) ;
252
259
}
@@ -404,7 +411,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
404
411
getAdUnits : ( ) => _adUnits ,
405
412
getAdUnitCodes : ( ) => _adUnitCodes ,
406
413
getBidRequests : ( ) => _bidderRequests ,
407
- getBidsReceived : ( ) => _bidsReceived ,
414
+ getBidsReceived : ( ) => _bidsReceived . toArray ( ) ,
408
415
getNoBids : ( ) => _noBids ,
409
416
getNonBids : ( ) => _nonBids ,
410
417
getFPD : ( ) => ortb2Fragments ,
0 commit comments