简体   繁体   English

Codeigniter填充下拉性能

[英]Codeigniter Populating Drop-Down Performance

I have a function in which I am populating a drop-down with about 100k items. 我有一个函数,其中填充了约10万个项目。

Obviously this is causing my page to hang for a bit while it's rendering. 显然,这导致我的页面在呈现时暂停了一段时间。

public function GetOrderDropDown($id){
    $CI =& get_instance();
    $CI->load->database();
    $qry = $CI->db->query("Select orderID, CONCAT('Order ID: ', orderID) As OrderName From vwSelectOrders Order By orderStarted Desc", FALSE);                    
    $res = $qry->result_array();
    if($res){
        $rCt = count($res);
        echo '<option value="0">- Please select an order -</option>';
        for($i = 0; $i < $rCt; ++$i){
            $sel = ($id == $res[$i]['orderID']) ? ' selected="selected"': null;
            echo '<option value="' . $res[$i]['orderID'] . '"' . $sel . '>' . $res[$i]['OrderName'] . '</option>';
            if($i % 50 === 0){
                ob_flush();
                flush();
            }
        }   
    }
}

The query itself runs pretty quick when applied in SQL MS, in fact when I print_r the returned array it's still pretty quick. 当应用到SQL MS中时,查询本身运行非常快,实际上,当我对返回的数组print_r进行查询时,它仍然非常快。 So I thought that by adding in a flush of the response at every 50 iterations would do the trick... and it does seem to hang less, but... I wonder if it could be better. 因此,我认为通过每隔50次迭代添加响应刷新就可以解决问题……而且它似乎挂得更少,但是……我想知道是否会更好。

This particular function is called in an ajaxed loaded page that displays a Loading graphic while the page is loaded... maybe I can force it to wait until the page is fully ready to be displayed? 在加载的页面中显示了一个加载图形时,在加载的页面中调用了此特定功能……也许我可以强迫它等待页面完全准备好显示出来?

// Load in a page
function LoadPage($url, $where){
    var $loading = '<div class="pageLoader">Loading...<br /><img src="/assets/images/ajax-loader.gif" alt="loading..." height="11" width="16" /></div>';
    var $container = jQuery((typeof($where) !== 'undefined') ? $where : '#content-container');
    var $t = Math.round(new Date().getTime() / 1000);
    var options = {
            url: $url + '?_=' + $t,
            cache: false,
            type: 'POST',
            beforeSend: function(){
                    $container.slideUp('slow', function(){
                        $container.slideDown('fast').html($loading);    
                    });
                },
            success: function(data, status, jqXhr){
                $container.slideUp('fast', function(){
                    $container.slideDown('fast').html(data);    
                });
            },
            complete: function(jqXhr, status){},
            error: function(jqXhr, status, error){
                $container.slideUp('fast', function(){
                    $container.slideDown('fast').html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><i class="fa fa-exclamation-triangle fa-4x pull-left"></i><p><strong>Danger Will Robinson!</strong><br />There was an issue pulling in this page. Our support team has been notified, please check back later.</p></div>');    
                });
            }
        };
    jQuery.ajax(options);
}

What else could I do, Firefox actually becomes un-responsive while it is loading...? 我还能做些什么,Firefox在加载时实际上变得无响应...?

In fact You shouldn't use <select> for 100k items. 实际上,您不应该对10万个项目使用<select> That's not user-fiendly. 这不是用户友好的。 Try to search autocomplete solutions. 尝试搜索自动完成解决方案。

About Your question: no, You can't add element with 100k child nodes without overloading browser. 关于您的问题:不,您不能在不使浏览器过载的情况下添加具有10万个子节点的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM