Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2022-02-28 13:44:49 +0300
committerGitHub <noreply@github.com>2022-02-28 13:44:49 +0300
commita20506b26bf646b0028cd92650b7184f361e0ca9 (patch)
tree112613e89e77e91d1fda9570aa514f59806a3d5c
parent38e79128cabc632794636aedce490ac5a383ac45 (diff)
parent5846d977a3cd438a47978ed8de6de41f5c91452f (diff)
Merge pull request #1156 from nextcloud/backport/1154/stable23v23.0.3rc2v23.0.3rc1
[stable23] Improve mass notification processing
-rw-r--r--lib/App.php3
-rw-r--r--lib/Handler.php34
-rw-r--r--tests/Unit/AppTest.php15
3 files changed, 35 insertions, 17 deletions
diff --git a/lib/App.php b/lib/App.php
index c14a6b5..6e5017b 100644
--- a/lib/App.php
+++ b/lib/App.php
@@ -54,8 +54,7 @@ class App implements IDeferrableApp {
$notificationId = $this->handler->add($notification);
try {
- $notificationToPush = $this->handler->getById($notificationId, $notification->getUser());
- $this->push->pushToDevice($notificationId, $notificationToPush);
+ $this->push->pushToDevice($notificationId, $notification);
} catch (NotificationNotFoundException $e) {
throw new \InvalidArgumentException('Error while preparing push notification');
}
diff --git a/lib/Handler.php b/lib/Handler.php
index ca7c18e..4d16908 100644
--- a/lib/Handler.php
+++ b/lib/Handler.php
@@ -108,11 +108,27 @@ class Handler {
}
$statement->closeCursor();
- foreach ($deleted as $user => $entries) {
- foreach ($entries as $entry) {
- $this->deleteById($entry['id'], (string) $user, $notifications[$entry['id']]);
+ $this->connection->beginTransaction();
+ try {
+ $shouldFlush = $this->manager->defer();
+
+ foreach ($notifications as $n) {
+ $this->manager->dismissNotification($n);
+ }
+
+ $notificationIds = array_keys($notifications);
+ foreach (array_chunk($notificationIds, 1000) as $chunk) {
+ $this->deleteIds($chunk);
}
+
+ if ($shouldFlush) {
+ $this->manager->flush();
+ }
+ } catch (\Throwable $e) {
+ $this->connection->rollBack();
+ throw $e;
}
+ $this->connection->commit();
return $deleted;
}
@@ -157,6 +173,18 @@ class Handler {
}
/**
+ * Delete the notification matching the given ids
+ *
+ * @param int[] $ids
+ */
+ public function deleteIds(array $ids): void {
+ $sql = $this->connection->getQueryBuilder();
+ $sql->delete('notifications')
+ ->where($sql->expr()->in('notification_id', $sql->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)));
+ $sql->executeStatement();
+ }
+
+ /**
* Get the notification matching the given id
*
* @param int $id
diff --git a/tests/Unit/AppTest.php b/tests/Unit/AppTest.php
index 4b97dd6..26d540d 100644
--- a/tests/Unit/AppTest.php
+++ b/tests/Unit/AppTest.php
@@ -53,8 +53,8 @@ class AppTest extends TestCase {
public function dataNotify() {
return [
- [23, 'user1'],
- [42, 'user2'],
+ [23],
+ [42],
];
}
@@ -62,21 +62,12 @@ class AppTest extends TestCase {
* @dataProvider dataNotify
*
* @param int $id
- * @param string $user
*/
- public function testNotify($id, $user) {
- $this->notification->expects($this->once())
- ->method('getUser')
- ->willReturn($user);
-
+ public function testNotify($id) {
$this->handler->expects($this->once())
->method('add')
->with($this->notification)
->willReturn($id);
- $this->handler->expects($this->once())
- ->method('getById')
- ->with($id, $user)
- ->willReturn($this->notification);
$this->push->expects($this->once())
->method('pushToDevice')
->with($id, $this->notification);