dimanche 19 juin 2016

Mysql: one big query vs several individual queries

I have a Yii2 project and I'm using a form with autocomplete feature. Something like the example in the documentation:

<?= $form->field($model, 'attibute')->widget(AutoComplete::classname(), [
    'clientOptions' => [
        'source' => ['value1', 'value2', 'value3'],
    ],
]) ?>

This widget needs that we populate the source with all autocomplete values and, in my scenario, the values are coming from another model.

I'm wondering if I should make a select to get all distinct values of this model in my db when the page loads or is better implement a way of, only while the user is typing, make a search of 10-20 values that match so far and update the result.

I'm not really concerned about the code, I'm sure I can find a lot of examples on the internet if I face any trouble. My problem is knowing what is best for this scenario. One big query with all values or individual ones each time the user type a new digit? I would like to undertand wich one suits better here (or another way) and why.

At the moment I have around 3k values stored in my db.

Aucun commentaire:

Enregistrer un commentaire