From a16d8097e8f0358df491a8c99c9f5881d8240936 Mon Sep 17 00:00:00 2001 From: Tim Yiu Date: Tue, 19 Sep 2023 11:15:05 -0700 Subject: [PATCH] fix: Do not track empty assignment events --- src/main/kotlin/assignment/AssignmentFilter.kt | 3 +++ src/test/kotlin/assignment/AssignmentFilterTest.kt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/assignment/AssignmentFilter.kt b/src/main/kotlin/assignment/AssignmentFilter.kt index c043eae..913ae53 100644 --- a/src/main/kotlin/assignment/AssignmentFilter.kt +++ b/src/main/kotlin/assignment/AssignmentFilter.kt @@ -12,6 +12,9 @@ internal class InMemoryAssignmentFilter(size: Int, ttlMillis: Long = DAY_MILLIS) private val cache = Cache(size, ttlMillis) override fun shouldTrack(assignment: Assignment): Boolean { + if (assignment.results.isEmpty()) { + return false + } val canonicalAssignment = assignment.canonicalize() val track = cache[canonicalAssignment] == null if (track) { diff --git a/src/test/kotlin/assignment/AssignmentFilterTest.kt b/src/test/kotlin/assignment/AssignmentFilterTest.kt index 29524a0..97b103f 100644 --- a/src/test/kotlin/assignment/AssignmentFilterTest.kt +++ b/src/test/kotlin/assignment/AssignmentFilterTest.kt @@ -89,7 +89,7 @@ class AssignmentFilterTest { ExperimentUser(userId = "user"), mapOf() ) - Assert.assertTrue(filter.shouldTrack(assignment1)) + Assert.assertFalse(filter.shouldTrack(assignment1)) val assignment2 = Assignment( ExperimentUser(userId = "user"), mapOf() @@ -99,7 +99,7 @@ class AssignmentFilterTest { ExperimentUser(userId = "different user"), mapOf() ) - Assert.assertTrue(filter.shouldTrack(assignment3)) + Assert.assertFalse(filter.shouldTrack(assignment3)) } @Test