Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation with hundreds of participants cause error on mass insert: Prepared statement contains too many placeholders #278

@silasrm

Description

@silasrm

Describe the bug
One of conversation has ~20k participants and when new message is added, the conversation generator crash with this mysql error: SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders

To Reproduce
Steps to reproduce the behavior:

  1. Normal instalation
  2. Add conversation
  3. Add hundreds of thousands of participants
  4. Create a message and see the error: SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders

Expected behavior
No error and all notifications created.

Screenshots
image
image

I need to refactor this createCustomNotifications method on src/Models/MessageNotification.php:

public static function createCustomNotifications($message, $conversation)
    {
        $notification = [];

        foreach ($conversation->participants as $participation) {
            $is_sender = ($message->participation_id == $participation->id) ? 1 : 0;

            $notification[] = [
                'messageable_id'   => $participation->messageable_id,
                'messageable_type' => $participation->messageable_type,
                'message_id'       => $message->id,
                'participation_id' => $participation->id,
                'conversation_id'  => $conversation->id,
                'is_seen'          => $is_sender,
                'is_sender'        => $is_sender,
                'created_at'       => $message->created_at,
            ];
        }

        self::insert($notification);
    }

How I do?

My idea: or chunk participant list in support number of MySQL, or work with jobs, sending the responsability to queue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions