简体   繁体   English

如何优化 CodeIgniter 查询性能?

[英]How to Optimize CodeIgniter Query Performance?

In one of my client project, I use CodeIgniter , MySQL and Bootstrap 4 and it works properly until recently when the volume of data raised dramatically.在我的一个客户项目中,我使用CodeIgniterMySQLBootstrap 4 ,直到最近数据量急剧增加时,它才能正常工作。 Due to large amount data, one list page requires almost one minute to load all data.由于数据量大,一个列表页需要将近一分钟的时间来加载所有数据。 The PHP code behind the list page is:列表页面背后的 PHP 代码是:

function getproductlist() {
    $query = $this->db->select('prd.id id, prd.brand_name brand_name, prd.strength strength, prd.status status, prd.remarks remarks, com.company_name company_name, cat.category_name category_name, dos.type_name type_name')->from('bsoft_pharma_product prd')->join('bsoft_pharma_company com', 'prd.company_id = com.id', 'left')->join('bsoft_pharma_product_category cat', 'prd.category_id = cat.id', 'left')->join('bsoft_pharma_product_type dos', 'prd.dosage_id = dos.id', 'left')->get();
    return $query;
}

Where bsoft_pharma_product table contains around 27000 data, bsoft_pharma_company table contains 170 data, bsoft_pharma_product_category table contains 1200 data and finally bsoft_pharma_product_type table contains 112 data.其中bsoft_pharma_product表包含大约27000 条数据, bsoft_pharma_company表包含170 条数据, bsoft_pharma_product_category表包含1200 条数据,最后bsoft_pharma_product_type表包含112 条数据。

Can anyone tell me how can I optimize my query?谁能告诉我如何优化我的查询?
Thanks谢谢

As I think there might be some solutions you have to try...因为我认为可能有一些解决方案你必须尝试......

Solution 1:解决方案1:

Load the page data only when user reach to the End of the page... Like: Google Images: [When we are viewing google images and we reach to the end of the page then some others images starts loading until the requested images types End.仅当用户到达页面末尾时才加载页面数据... 喜欢:谷歌图片:[当我们查看谷歌图片并到达页面末尾时,其他一些图片开始加载,直到请求的图片类型结束.

Solution 2:解决方案2:

Convert the data to pagination like 20 / 30 records per page.将数据转换为分页,如每页 20 / 30 条记录。

Solution 3:解决方案3:

Use some logo / animation loading tricks... like:使用一些徽标/动画加载技巧......例如:

Use JavaScript to check the page loading percentage and then load something like: animation or company logo etc, so if the user have to wait then they don't feel boar or thinks that there is some issue in the page.使用 JavaScript 检查页面加载百分比,然后加载诸如:动画或公司徽标等内容,因此如果用户不得不等待,那么他们不会感到野猪或认为页面中存在某些问题。

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

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