Skip to content

Commit 24bde75

Browse files
committed
Integrate 14 day confirmation pixel
1 parent 40af82b commit 24bde75

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/pixels/OptOutConfirmationReporter.kt

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,55 @@ class RealOptOutConfirmationReporter @Inject constructor(
5151

5252
if (activeBrokers.isEmpty() || allValidRequestedOptOutJobs.isEmpty()) return@withContext
5353

54-
attemptFire7dayPixel(allValidRequestedOptOutJobs, activeBrokers)
54+
allValidRequestedOptOutJobs.also {
55+
it.attemptFirePixelForConfirmationDay(
56+
activeBrokers,
57+
7,
58+
{ jobRecord -> jobRecord.confirmation7dayReportSentDateMs == 0L },
59+
{ brokerUrl -> pixelSender.reportBrokerOptOutConfirmed7Days(brokerUrl) },
60+
{ brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed7Days(brokerUrl) },
61+
{ jobRecord, now ->
62+
pirSchedulingRepository.markOptOutDay7ConfirmationPixelSent(jobRecord.extractedProfileId, now)
63+
},
64+
)
65+
66+
it.attemptFirePixelForConfirmationDay(
67+
activeBrokers,
68+
14,
69+
{ jobRecord -> jobRecord.confirmation14dayReportSentDateMs == 0L },
70+
{ brokerUrl -> pixelSender.reportBrokerOptOutConfirmed14Days(brokerUrl) },
71+
{ brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed14Days(brokerUrl) },
72+
{ jobRecord, now ->
73+
pirSchedulingRepository.markOptOutDay14ConfirmationPixelSent(jobRecord.extractedProfileId, now)
74+
},
75+
)
76+
}
5577
}
5678
}
5779

58-
private suspend fun attemptFire7dayPixel(
59-
allValidRequestedOptOutJobs: List<OptOutJobRecord>,
80+
private suspend fun List<OptOutJobRecord>.attemptFirePixelForConfirmationDay(
6081
activeBrokers: Map<String, Broker>,
82+
confirmationDay: Long,
83+
jobRecordFilter: (OptOutJobRecord) -> Boolean,
84+
emitConfirmPixel: (String) -> Unit,
85+
emitUnconfirmPixel: (String) -> Unit,
86+
markOptOutJobRecordReporting: suspend (OptOutJobRecord, Long) -> Unit,
6187
) {
6288
val now = currentTimeProvider.currentTimeMillis()
63-
val optOutsForSevenDayPixel = allValidRequestedOptOutJobs.filter {
64-
it.daysPassedSinceSubmission(now, 7) && it.confirmation7dayReportSentDateMs == 0L
89+
val optOutsForSevenDayPixel = this.filter {
90+
it.daysPassedSinceSubmission(now, confirmationDay) && jobRecordFilter(it)
6591
}
6692

6793
optOutsForSevenDayPixel.forEach { optOutJobRecord ->
6894
val brokerUrl = activeBrokers[optOutJobRecord.brokerName]?.url ?: return@forEach
6995

7096
if (optOutJobRecord.status == REMOVED) {
71-
pixelSender.reportBrokerOptOutConfirmed7Days(brokerUrl)
97+
emitConfirmPixel(brokerUrl)
7298
} else {
73-
pixelSender.reportBrokerOptOutUnconfirmed7Days(brokerUrl)
99+
emitUnconfirmPixel(brokerUrl)
74100
}
75101

76-
pirSchedulingRepository.markOptOutDay7ConfirmationPixelSent(optOutJobRecord.extractedProfileId, now)
102+
markOptOutJobRecordReporting(optOutJobRecord, now)
77103
}
78104
}
79105

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/PirSchedulingRepository.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ interface PirSchedulingRepository {
130130
extractedProfileId: Long,
131131
timestampMs: Long,
132132
)
133+
134+
suspend fun markOptOutDay14ConfirmationPixelSent(
135+
extractedProfileId: Long,
136+
timestampMs: Long,
137+
)
133138
}
134139

135140
@ContributesBinding(
@@ -334,6 +339,15 @@ class RealPirSchedulingRepository @Inject constructor(
334339
}
335340
}
336341

342+
override suspend fun markOptOutDay14ConfirmationPixelSent(
343+
extractedProfileId: Long,
344+
timestampMs: Long,
345+
) {
346+
withContext(dispatcherProvider.io()) {
347+
jobSchedulingDao()?.update14DayConfirmationReportSentDate(extractedProfileId, timestampMs)
348+
}
349+
}
350+
337351
private fun ScanJobRecordEntity.toRecord(): ScanJobRecord =
338352
ScanJobRecord(
339353
brokerName = this.brokerName,

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/db/JobSchedulingDao.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,16 @@ interface JobSchedulingDao {
130130
extractedProfileId: Long,
131131
newDate: Long,
132132
)
133+
134+
@Query(
135+
"""
136+
UPDATE pir_optout_job_record
137+
SET reporting_fourteenDayConfirmationReportSentDateMs = :newDate
138+
WHERE extractedProfileId = :extractedProfileId
139+
""",
140+
)
141+
fun update14DayConfirmationReportSentDate(
142+
extractedProfileId: Long,
143+
newDate: Long,
144+
)
133145
}

0 commit comments

Comments
 (0)