Skip to content

Commit 498afc2

Browse files
Mini optimization.
1 parent 51ef521 commit 498afc2

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,29 @@ public async Task DidReceivePullRefreshRequestAsync(PullRefreshOptions? options
8181
await TrackNotificationsAsync(notifications.ToArray());
8282
}
8383

84-
private async Task<IEnumerable<UserNotificationDto>> GetPendingNotificationsAsync(int take, TimeSpan period)
84+
private async Task<IEnumerable<UserNotificationDto>> GetPendingNotificationsAsync(int take, TimeSpan maxAge)
8585
{
8686
try
8787
{
8888
var notificationPending = await Notifications.GetMyNotificationsAsync(take: take);
89-
var notificationSeen = await GetSeenNotificationsAsync();
9089

91-
var utcNow = DateTimeOffset.UtcNow;
90+
if (notificationPending.Items.Count == 0)
91+
{
92+
return Enumerable.Empty<UserNotificationDto>();
93+
}
94+
95+
var currentSeen = await GetSeenNotificationsAsync();
96+
var currentTime = DateTimeOffset.UtcNow;
97+
98+
bool IsRecent(DateTimeOffset date)
99+
{
100+
return (currentTime - date.UtcDateTime) <= maxAge;
101+
}
92102

93-
var pendingNotifications = notificationPending
94-
.Items
95-
.Where(x => !notificationSeen.Contains(x.Id))
96-
.Where(x => (utcNow - x.Created.UtcDateTime) <= period)
103+
var pendingNotifications = notificationPending.Items
104+
.Where(n => !n.IsSeen)
105+
.Where(n => !currentSeen.Contains(n.Id))
106+
.Where(n => IsRecent(n.Created))
97107
.OrderBy(x => x.Created)
98108
.ToArray();
99109

0 commit comments

Comments
 (0)