You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// This is much faster than searching through all historical notifications
57
+
val queryStartTime =System.currentTimeMillis()
58
+
val existingUnreadNotifications = realm.where(RealmNotification::class.java)
59
+
.equalTo("userId", actualUserId)
60
+
.equalTo("isRead", false)
61
+
.findAll()
71
62
72
-
android.util.Log.d("NotificationRepository", "createNotificationsIfMissing: Found ${existingNotifications.size}existing notifications")
63
+
android.util.Log.d("NotificationRepository", "createNotificationsIfMissing: Found ${existingUnreadNotifications.size}unread notifications in ${System.currentTimeMillis() - queryStartTime}ms")
73
64
74
65
// Create a set of existing notification keys for O(1) lookup
75
-
val existingKeys =existingNotifications.mapNotNull { existing ->
66
+
val existingKeys =existingUnreadNotifications.mapNotNull { existing ->
76
67
if (existing.relatedId !=null) {
77
68
"${existing.type}:${existing.relatedId}"
78
69
} else {
@@ -82,6 +73,7 @@ class NotificationRepositoryImpl @Inject constructor(
82
73
83
74
val now =Date()
84
75
var createdCount =0
76
+
var skippedCount =0
85
77
86
78
// Batch create all missing notifications in a single transaction
87
79
notifications.forEach { notification ->
@@ -100,11 +92,13 @@ class NotificationRepositoryImpl @Inject constructor(
100
92
this.createdAt = now
101
93
}
102
94
createdCount++
95
+
} else {
96
+
skippedCount++
103
97
}
104
98
}
105
99
106
100
val endTime =System.currentTimeMillis()
107
-
android.util.Log.d("NotificationRepository", "createNotificationsIfMissing: Created $createdCount new notifications in ${endTime - startTime}ms")
101
+
android.util.Log.d("NotificationRepository", "createNotificationsIfMissing: Created $createdCount new, skipped $skippedCount existing in ${endTime - startTime}ms total")
0 commit comments