|
16 | 16 | package org.sakaiproject.messaging.impl; |
17 | 17 |
|
18 | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | + |
19 | 20 | import lombok.Setter; |
20 | 21 | import lombok.extern.slf4j.Slf4j; |
| 22 | + |
21 | 23 | import nl.martijndwars.webpush.Notification; |
22 | 24 | import nl.martijndwars.webpush.PushService; |
23 | 25 | import nl.martijndwars.webpush.Subscription; |
24 | 26 | import nl.martijndwars.webpush.Utils; |
| 27 | + |
25 | 28 | import org.apache.commons.lang3.StringUtils; |
26 | 29 | import org.apache.commons.text.StringEscapeUtils; |
27 | 30 | import org.apache.http.HttpResponse; |
| 31 | + |
28 | 32 | import org.bouncycastle.jce.ECNamedCurveTable; |
29 | 33 | import org.bouncycastle.jce.interfaces.ECPrivateKey; |
30 | 34 | import org.bouncycastle.jce.interfaces.ECPublicKey; |
31 | 35 | import org.bouncycastle.jce.provider.BouncyCastleProvider; |
32 | 36 | import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; |
| 37 | + |
33 | 38 | import org.sakaiproject.component.api.ServerConfigurationService; |
34 | 39 | import org.sakaiproject.email.api.DigestService; |
35 | 40 | import org.sakaiproject.email.api.EmailService; |
|
66 | 71 | import org.sakaiproject.user.api.UserNotDefinedException; |
67 | 72 | import org.sakaiproject.util.ResourceLoader; |
68 | 73 | import org.sakaiproject.util.api.FormattedText; |
| 74 | + |
69 | 75 | import org.springframework.beans.factory.annotation.Autowired; |
70 | 76 | import org.springframework.beans.factory.annotation.Qualifier; |
| 77 | +import org.springframework.data.domain.Page; |
| 78 | +import org.springframework.data.domain.PageRequest; |
71 | 79 | import org.springframework.transaction.TransactionStatus; |
72 | 80 | import org.springframework.transaction.annotation.Transactional; |
73 | 81 | import org.springframework.transaction.support.TransactionCallbackWithoutResult; |
|
80 | 88 | import java.security.KeyPair; |
81 | 89 | import java.security.KeyPairGenerator; |
82 | 90 | import java.security.Security; |
83 | | -import java.time.Duration; |
84 | 91 | import java.time.Instant; |
85 | 92 | import java.util.ArrayList; |
86 | 93 | import java.util.Base64; |
@@ -580,31 +587,30 @@ private void pushToAllUsers(UserNotificationTransferBean bean) { |
580 | 587 |
|
581 | 588 | executor.execute(() -> { |
582 | 589 |
|
583 | | - int pageSize = 100; |
584 | | - int first = 1; |
585 | | - int last = first + pageSize; |
586 | | - int total = userDirectoryService.countUsers(); |
587 | | - int done = 0; |
588 | | - |
589 | 590 | UserNotificationTransferBean un = new UserNotificationTransferBean(); |
590 | 591 | un.from = bean.from; |
591 | 592 | un.event = bean.event; |
592 | 593 | un.ref = bean.ref; |
593 | 594 | un.title = bean.title; |
594 | 595 |
|
595 | | - while (done < total) { |
| 596 | + int pageNumber = 0; |
| 597 | + int pageSize = 1; |
596 | 598 |
|
597 | | - List<User> users = userDirectoryService.getUsers(first, last); |
| 599 | + Map<String, String> done = new HashMap<>(); |
| 600 | + Page<PushSubscription> page = pushSubscriptionRepository.findAll(PageRequest.of(pageNumber, pageSize)); |
| 601 | + while (page.getTotalElements() > 0) { |
| 602 | + page.getContent().forEach(ps -> { |
598 | 603 |
|
599 | | - users.forEach(u -> { |
600 | | - |
601 | | - un.to = u.getId(); |
602 | | - push(decorateNotification(un)); |
| 604 | + String userId = ps.getUserId(); |
| 605 | + if (!done.containsKey(userId)) { |
| 606 | + un.to = ps.getUserId(); |
| 607 | + push(decorateNotification(un)); |
| 608 | + done.put(userId, ""); |
| 609 | + } |
603 | 610 | }); |
604 | 611 |
|
605 | | - first = last + 1; |
606 | | - last = first + pageSize; |
607 | | - done += users.size(); |
| 612 | + pageNumber += 1; |
| 613 | + page = pushSubscriptionRepository.findAll(PageRequest.of(pageNumber, pageSize)); |
608 | 614 | } |
609 | 615 | }); |
610 | 616 | } |
|
0 commit comments