File tree Expand file tree Collapse file tree 1 file changed +5
-17
lines changed
Expand file tree Collapse file tree 1 file changed +5
-17
lines changed Original file line number Diff line number Diff line change @@ -242,11 +242,12 @@ export async function postAds(params: {
242242 return NextResponse . json ( { ad : null , variant } , { status : 200 } )
243243 }
244244
245- // Store all returned ads in the database
245+ // Store all returned ads in the database (skip duplicates via imp_url unique constraint)
246246 for ( const ad of ads ) {
247247 const payout = ad . payout || DEFAULT_PAYOUT
248- try {
249- await db . insert ( schema . adImpression ) . values ( {
248+ await db
249+ . insert ( schema . adImpression )
250+ . values ( {
250251 user_id : userId ,
251252 ad_text : ad . adText ,
252253 title : ad . title ,
@@ -258,20 +259,7 @@ export async function postAds(params: {
258259 payout : String ( payout ) ,
259260 credits_granted : 0 ,
260261 } )
261- } catch ( error ) {
262- logger . warn (
263- {
264- userId,
265- impUrl : ad . impUrl ,
266- status : response . status ,
267- error :
268- error instanceof Error
269- ? { name : error . name , message : error . message }
270- : error ,
271- } ,
272- '[ads] Failed to create ad_impression record (likely duplicate)' ,
273- )
274- }
262+ . onConflictDoNothing ( )
275263 }
276264
277265 // Strip payout from all ads before returning to client
You can’t perform that action at this time.
0 commit comments