Add pre-built option list to webform

2018-03-09 08:48:58

I am looking to add a pre-built options list, based on a query. I crafted the function nicely with the below code

function mitacan_webform_select_options_info() {

$items = [];

if (function_exists('basliklariAl')) {

$items['addresses'] = array(

'title' => 'Stok Kodları',

'options callback' => 'basliklariAl'

);

}

return $items;

}

function basliklariAl($component, $flat, $arguments) {

$nodes = [];

$select = db_select('node','n')

->fields('n',[

'nid',

'title'

])

->condition('type','urun')

->execute()

->fetchAll();

foreach($select as $n) {

$nodes[$n->nid] = $n->title;

}

return $nodes;

}

This is very slow, mostly because there are about 10k records. What can I do to optimise the process?