mirror of
https://github.com/flarum/core.git
synced 2025-08-04 07:27:39 +02:00
perf: speed up post creation time (#3808)
* chore: drop unused visibility checking in notif syncer Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * perf: eager load parsed mentions Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * perf: eager load some relations needed for visibility checking Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * perf: trigger mentions notifications in a queueable job Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * fix: broken tag mentions Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> --------- Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
@@ -85,7 +85,7 @@ class Formatter
|
||||
* @param string $text
|
||||
* @param mixed $context
|
||||
* @param User|null $user
|
||||
* @return string
|
||||
* @return string the parsed XML
|
||||
*/
|
||||
public function parse($text, $context = null, User $user = null)
|
||||
{
|
||||
|
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace Flarum\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\Driver\NotificationDriverInterface;
|
||||
use Flarum\User\User;
|
||||
@@ -75,12 +74,6 @@ class NotificationSyncer
|
||||
continue;
|
||||
}
|
||||
|
||||
// To add access checking on notification subjects, we first attempt
|
||||
// to load visible subjects to this user.
|
||||
if (! $this->userCanSeeSubject($user, $blueprint->getSubject())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existing = $toDelete->first(function ($notification) use ($user) {
|
||||
return $notification->user_id === $user->id;
|
||||
});
|
||||
@@ -168,18 +161,6 @@ class NotificationSyncer
|
||||
Notification::whereIn('id', $ids)->update(['is_deleted' => $isDeleted]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check access to determine if the recipient is allowed to receive the notification.
|
||||
*/
|
||||
protected function userCanSeeSubject(User $user, ?AbstractModel $subject): bool
|
||||
{
|
||||
if ($subject && method_exists($subject, 'registerVisibilityScoper')) {
|
||||
return (bool) $subject->newQuery()->whereVisibleTo($user)->find($subject->id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a notification driver to the list.
|
||||
*
|
||||
|
@@ -10,15 +10,11 @@
|
||||
namespace Flarum\Tests\integration\notification;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Api\Serializer\BasicDiscussionSerializer;
|
||||
use Flarum\Api\Serializer\BasicPostSerializer;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\Notification;
|
||||
use Flarum\Notification\NotificationSyncer;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
@@ -50,35 +46,6 @@ class NotificationSyncerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider visibleSubjectsProvider
|
||||
* @param class-string<AbstractModel> $subjectClass
|
||||
* @test
|
||||
*/
|
||||
public function can_receive_notification_for_visible_subjects(string $subjectClass, int $subjectId, string $serializer)
|
||||
{
|
||||
$this->expect_notification_count_from_sending_notification_type_with_subject(
|
||||
2,
|
||||
$subjectClass,
|
||||
$subjectId,
|
||||
$serializer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invisibleSubjectsProvider
|
||||
* @test
|
||||
*/
|
||||
public function cannot_receive_notification_for_restricted_subjects(string $subjectClass, int $subjectId, string $serializer)
|
||||
{
|
||||
$this->expect_notification_count_from_sending_notification_type_with_subject(
|
||||
0,
|
||||
$subjectClass,
|
||||
$subjectId,
|
||||
$serializer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<AbstractModel> $subjectClass
|
||||
*/
|
||||
@@ -112,23 +79,6 @@ class NotificationSyncerTest extends TestCase
|
||||
->count()
|
||||
);
|
||||
}
|
||||
|
||||
public function visibleSubjectsProvider()
|
||||
{
|
||||
return [
|
||||
[Post::class, 1, BasicPostSerializer::class],
|
||||
[Discussion::class, 1, BasicDiscussionSerializer::class],
|
||||
];
|
||||
}
|
||||
|
||||
public function invisibleSubjectsProvider()
|
||||
{
|
||||
return [
|
||||
[Post::class, 2, BasicPostSerializer::class],
|
||||
[Discussion::class, 2, BasicDiscussionSerializer::class],
|
||||
[Post::class, 3, BasicPostSerializer::class],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class CustomNotificationType implements BlueprintInterface
|
||||
|
Reference in New Issue
Block a user