This is a pretty active site with over 50,000 customers in the database. There are quite a few inactive customers, I wonder if I delete the inactive customers from the oc_customer table if that will help? Will that have any negative impact?
On a side note, we upgraded a OC 2.0 site to OC 3.0. For some reason it was a little slow, but I exported the database in MySQL Workshop and then re-imported it, and ever since the website has ran really quickly! So weird that helped somehow!
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
As you please. Check the DB optimization then.websiteworld wrote: ↑Mon Mar 14, 2022 2:48 amNot likely and it was doing this in the sandbed before it even went live.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Hi.websiteworld wrote: ↑Mon Mar 14, 2022 3:28 amI optimized the OC_Customer table and it's twice as fast. Still slower than I'd like, but much better at about 4 seconds. Thanks.
You need to profile the SQL authorization request using EXPLAIN. Perhaps simple or composite indexes will solve this problem.
My FREE extensions in marketplace. [ security | flexibility | speedup ]
Something else must have gone wrong on your website.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Great post-paulfeakins wrote: ↑Tue Mar 15, 2022 12:17 amCheck against this list of possible reasons: https://www.antropy.co.uk/blog/how-to-s ... ed-issues/
https://www.antropy.co.uk/blog/opencart ... very-slow/
I can remember reading about creating the indexes years ago, and had forgotten about that. I've been using OC since 1.5. Are all the recommended ones up to date for OC3.x? We don't have a table called product_tag anymore.
On a side note, I noticed you had mentioned Nitrocache when we used in OC2.0 which they retired. I installed DatabaseSpeed up and used MemCached with it, I think it works pretty well! https://isenselabs.com/products/view/da ... ed-booster
I noticed there were no indexes for the customer table, should those have indexes too? That seems like it would affect the customer login times.
https://github.com/IP-CAM/Optimize-Data ... .3.x-v.3.x
My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
How do we know if it's safe? What exactly is it doing? Here is the code:IP_CAM wrote: ↑Sat Mar 19, 2022 3:39 amYou could try this one, to possibly get some better results:
https://github.com/IP-CAM/Optimize-Data ... .3.x-v.3.x
Code: Select all
<?php
class ControllerExtensionModuleDboptim extends Controller {
public function index() {
$data = array();
$result = $this->db->query('show tables');
$data['tables'] = array();
foreach ($result->rows as $row) {
$data['tables'][ $row[key($row)] ] = null;
}
// if ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($_POST['optimize']) && is_array($_POST['optimize']) && ! empty($_POST['optimize'])) {
// foreach($_POST['optimize'] as $table) {
foreach ($data['tables'] as $table => $value) {
$result = $this->db->query('optimize table '. $table);
$data['tables'][$table] = $result->rows[0]['Msg_text'];
}
// }
// }
$this->load->language('extension/module/dboptim');
$this->document->setTitle($this->language->get('heading_title'));
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/dboptim', 'user_token=' . $this->session->data['user_token'], true)
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/dboptim', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true)
);
}
if (!isset($this->request->get['module_id'])) {
$data['action'] = $this->url->link('extension/module/dboptim', 'user_token=' . $this->session->data['user_token'], true);
} else {
$data['action'] = $this->url->link('extension/module/dboptim', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true);
}
$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/module/dboptim', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/dboptim')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
In addition, is_array lookup should be used after the !empty, not reversed and isset would not be needed in there.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Beside the former comment: yes it's safe.websiteworld wrote: ↑Sat Mar 19, 2022 3:56 amHow do we know if it's safe? What exactly is it doing? Here is the code:
Code: Select all
<?php class ControllerExtensionModuleDboptim extends Controller { public function index() { $data = array(); $result = $this->db->query('show tables'); $data['tables'] = array(); foreach ($result->rows as $row) { $data['tables'][ $row[key($row)] ] = null; } // if ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($_POST['optimize']) && is_array($_POST['optimize']) && ! empty($_POST['optimize'])) { // foreach($_POST['optimize'] as $table) { foreach ($data['tables'] as $table => $value) { $result = $this->db->query('optimize table '. $table); $data['tables'][$table] = $result->rows[0]['Msg_text']; } // } // } }
And what this code does:
Running a simple
Code: Select all
OPTIMIZE table
which is a native MySQL command.
on previous selected tables (in a form):
Code: Select all
$_POST['optimize']
But it's funny to see "a well coded script" ..
At the beginning you get the tables with that:
Code: Select all
$result = $this->db->query('show tables');
Code: Select all
if ($this->request->server['REQUEST_METHOD'] == 'POST'
Code: Select all
foreach ($data['tables'] as $table => $value) {
Generally it would be better (and faster) not to call each table, instead use the IN syntax on one call.
And please, not show tables should be SHOW TABLES (optimize the same).
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
My FREE extensions in marketplace. [ security | flexibility | speedup ]
Nowhere to be said it wasn't safe. What was said in there is that running the script such ways would be pointless.OSWorX wrote: ↑Sat Mar 19, 2022 11:31 amBeside the former comment: yes it's safe.websiteworld wrote: ↑Sat Mar 19, 2022 3:56 amHow do we know if it's safe? What exactly is it doing? Here is the code:
Code: Select all
<?php class ControllerExtensionModuleDboptim extends Controller { public function index() { $data = array(); $result = $this->db->query('show tables'); $data['tables'] = array(); foreach ($result->rows as $row) { $data['tables'][ $row[key($row)] ] = null; } // if ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($_POST['optimize']) && is_array($_POST['optimize']) && ! empty($_POST['optimize'])) { // foreach($_POST['optimize'] as $table) { foreach ($data['tables'] as $table => $value) { $result = $this->db->query('optimize table '. $table); $data['tables'][$table] = $result->rows[0]['Msg_text']; } // } // } }
And what this code does:
Running a simpleCode: Select all
OPTIMIZE table
which is a native MySQL command.
on previous selected tables (in a form):btw: if you already switched your tables from MyISAM to InnoDB, the OPTIMIZE command is useless.Code: Select all
$_POST['optimize']
But it's funny to see "a well coded script" ..
At the beginning you get the tables with that:later you check if something is coming from a form (here commented)Code: Select all
$result = $this->db->query('show tables');
and then you use this:Code: Select all
if ($this->request->server['REQUEST_METHOD'] == 'POST'
(using the former query).Code: Select all
foreach ($data['tables'] as $table => $value) {
Generally it would be better (and faster) not to call each table, instead use the IN syntax on one call.
And please, not show tables should be SHOW TABLES (optimize the same).
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
For future reference adding indexes solved my issue. The site is lightning fast now! Product_tag was skipped in my case.paulfeakins wrote: ↑Tue Mar 15, 2022 12:17 amCheck against this list of possible reasons: https://www.antropy.co.uk/blog/how-to-s ... ed-issues/
Code: Select all
ALTER TABLE `category` ADD INDEX ( `parent_id` );
ALTER TABLE `category` ADD INDEX ( `top` );
ALTER TABLE `category` ADD INDEX ( `sort_order` );
ALTER TABLE `category` ADD INDEX ( `status` );
ALTER TABLE `option` ADD INDEX ( `sort_order` );
ALTER TABLE `option_description` ADD INDEX ( `name` );
ALTER TABLE `option_value` ADD INDEX ( `option_id` );
ALTER TABLE `option_value_description` ADD INDEX ( `option_id` );
ALTER TABLE `order` ADD INDEX ( `customer_id` );
ALTER TABLE `product` ADD INDEX ( `model` );
ALTER TABLE `product` ADD INDEX ( `sku` );
ALTER TABLE `product` ADD INDEX ( `upc` );
ALTER TABLE `product` ADD INDEX ( `manufacturer_id` );
ALTER TABLE `product` ADD INDEX ( `sort_order` );
ALTER TABLE `product` ADD INDEX ( `status` );
ALTER TABLE `product_option` ADD INDEX ( `option_id` );
ALTER TABLE `product_option_value` ADD INDEX ( `product_option_id` );
ALTER TABLE `product_option_value` ADD INDEX ( `product_id` );
ALTER TABLE `product_option_value` ADD INDEX ( `option_id` );
ALTER TABLE `product_option_value` ADD INDEX ( `option_value_id` );
ALTER TABLE `product_tag` ADD INDEX ( `product_id` );
ALTER TABLE `product_tag` ADD INDEX ( `tag` );
ALTER TABLE `url_alias` ADD INDEX ( `query` );
ALTER TABLE `url_alias` ADD INDEX ( `keyword` );
ALTER TABLE `user` ADD INDEX ( `username` );
ALTER TABLE `user` ADD INDEX ( `password` );
ALTER TABLE `user` ADD INDEX ( `email` );
Guess you have to buy new glasses .. ?!straightlight wrote: ↑Sat Mar 19, 2022 9:22 pmNowhere to be said it wasn't safe. What was said in there is that running the script such ways would be pointless.
Please read better next time before wasting the space here.websiteworld wrote: ↑Sat Mar 19, 2022 3:56 amHow do we know if it's safe? What exactly is it doing?
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Not to forget to mention the database table prefixes that may differ between the users.websiteworld wrote: ↑Sat Mar 19, 2022 9:41 pmFor future reference adding indexes solved my issue. The site is lightning fast now! Product_tag was skipped in my case.paulfeakins wrote: ↑Tue Mar 15, 2022 12:17 amCheck against this list of possible reasons: https://www.antropy.co.uk/blog/how-to-s ... ed-issues/
Code: Select all
ALTER TABLE `category` ADD INDEX ( `parent_id` ); ALTER TABLE `category` ADD INDEX ( `top` ); ALTER TABLE `category` ADD INDEX ( `sort_order` ); ALTER TABLE `category` ADD INDEX ( `status` ); ALTER TABLE `option` ADD INDEX ( `sort_order` ); ALTER TABLE `option_description` ADD INDEX ( `name` ); ALTER TABLE `option_value` ADD INDEX ( `option_id` ); ALTER TABLE `option_value_description` ADD INDEX ( `option_id` ); ALTER TABLE `order` ADD INDEX ( `customer_id` ); ALTER TABLE `product` ADD INDEX ( `model` ); ALTER TABLE `product` ADD INDEX ( `sku` ); ALTER TABLE `product` ADD INDEX ( `upc` ); ALTER TABLE `product` ADD INDEX ( `manufacturer_id` ); ALTER TABLE `product` ADD INDEX ( `sort_order` ); ALTER TABLE `product` ADD INDEX ( `status` ); ALTER TABLE `product_option` ADD INDEX ( `option_id` ); ALTER TABLE `product_option_value` ADD INDEX ( `product_option_id` ); ALTER TABLE `product_option_value` ADD INDEX ( `product_id` ); ALTER TABLE `product_option_value` ADD INDEX ( `option_id` ); ALTER TABLE `product_option_value` ADD INDEX ( `option_value_id` ); ALTER TABLE `product_tag` ADD INDEX ( `product_id` ); ALTER TABLE `product_tag` ADD INDEX ( `tag` ); ALTER TABLE `url_alias` ADD INDEX ( `query` ); ALTER TABLE `url_alias` ADD INDEX ( `keyword` ); ALTER TABLE `user` ADD INDEX ( `username` ); ALTER TABLE `user` ADD INDEX ( `password` ); ALTER TABLE `user` ADD INDEX ( `email` );
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
The question was answered as the posted code itself is not about safe / unsafe as replied from my previous post. I could add, however, that there's nothing wrong regarding the code practice nor code security other than to mention to use the: $this->request->post instead of using $_POST in OC which nobody did, so far.OSWorX wrote: ↑Sat Mar 19, 2022 9:48 pmGuess you have to buy new glasses .. ?!straightlight wrote: ↑Sat Mar 19, 2022 9:22 pmNowhere to be said it wasn't safe. What was said in there is that running the script such ways would be pointless.Please read better next time before wasting the space here.websiteworld wrote: ↑Sat Mar 19, 2022 3:56 amHow do we know if it's safe? What exactly is it doing?
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: Bing [Bot] and 18 guests