Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory is exhausted when compose a message #23

Open
Gustik opened this issue May 21, 2018 · 1 comment
Open

memory is exhausted when compose a message #23

Gustik opened this issue May 21, 2018 · 1 comment

Comments

@Gustik
Copy link

Gustik commented May 21, 2018

action message/message/compose show this error
Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)

40K users

@Gustik
Copy link
Author

Gustik commented May 21, 2018

Add action in MessageController

public function actionRecipients($q = null, $id = null)
    {
        \Yii::$app->response->format = Response::FORMAT_JSON;
        $out = ['results' => ['id' => '', 'username' => '']];
        if (!is_null($q)) {
            $data = User::find()->andFilterWhere(['like', 'username', $q])
                ->orderBy(['username' => SORT_DESC])->all();

            $out['results'] = array_values($data);
        } elseif ($id > 0) {
            $out['results'] = ['id' => $id, 'username' => User::findOne($id)->username];
        }
        return $out;
    }

and select users widget look like this

echo $form->field($model, 'to')->widget(Select2::className(), [
                'pluginOptions' => [
                    'allowClear' => true,
                    'minimumInputLength' => 3,
                    'ajax' => [
                        'url' => \yii\helpers\Url::to(['/message/message/recipients']),
                        'dataType' => 'json',
                        'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                        'processResults' => new JsExpression('
                                function (data, params) {
                                    return {
                                        results: $.map(data["results"], function (item) {
                                            return {
                                                id: item.id,
                                                text: item.username,
                                            };
                                        }),
                                        pagination: false,
                                    };
                                }
                            '),
                    ],
                    'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                    'templateResult' => new JsExpression('function(user) { return user.text; }'),
                    'templateSelection' => new JsExpression('function (user) { return user.text; }'),
                ],
                'showToggleAll' => false, # avoid accidental or malicious spam
                'options' => [
                    'multiple' => $allow_multiple,
                    'placeholder' => Yii::t('message', $allow_multiple ? 'Choose one or more recipients' : 'Choose the recipient'),
                ],
                'language' => Yii::$app->language ? Yii::$app->language : null,
            ]); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant