Когда у меня есть один пользователь notifiable
, вставляется одна запись в таблице notifications
вместе с отправленным mail
/sms
, который отлично работает через каналы.
Проблема заключается в том, что у меня есть коллекция user
, список из 1k пользователей, следующих за мной, и я публикую обновление. Вот что происходит при использовании признака notifiable
, как предложено для многопользовательского случая:
- 1k
mails
/sms
отправлено (проблема здесь отсутствует) - 1k записей уведомлений, добавленных в таблицу DB
notifications
Кажется, что добавление 1k уведомлений в таблицу DB notifications
не является оптимальным решением. Поскольку данные toArray
совпадают, а все остальное в таблице DB notifications
одинаково для строк 1k, разница только равна notifiable_id
user
notifiable_type
.
Оптимальное решение из коробки:
- Laravel подберет тот факт, что он
array
notifiable_type
- Сохраните уведомление одиночное как
notifiable_type
user_array
илиuser
с помощьюnotifiable_id
0 (ноль будет использоваться только для обозначения его нескольких уведомляемых пользователей) -
Создайте/используйте другую таблицу
notifications_read
, используяnotification_id
, только что созданный какforeign_key
, и вставьте строки 1k только из этих полей:notification_id
notifiable_id
notifiable_type
read_at
Я надеюсь, что уже есть способ сделать это, поскольку я нахожусь в этом пункте в своем приложении и хотел бы использовать встроенные уведомления и каналы для этой ситуации, поскольку я стреляю emails
/sms
уведомления, которые, как мне кажется, могут повторяться в 1 раз, но это запись одних и тех же данных в базу данных, которая является проблемой, которая нуждается в оптимизации.
Любые мысли/идеи, как действовать в этой ситуации?