Hi,
I stumbled on a little bug on the most recent version. The Sales Widgets were not calculated if set to week / day. Month and Year worked fine.
I took a look into it and found the issuing lines in DashboardWidgets/Statistics.php
the code in line 150 is not optimal.
if ($range === 'day')
return 'DATE(date_added) = '.date('Y-m-d');
if ($range === 'week')
return 'WEEK(date_added) = '.date('W');
if ($range === 'month')
return 'MONTH(date_added) = '.date('m');
if ($range === 'year')
return 'YEAR(date_added) = '.date('Y');
The mysql database will calculate the DATE(), MONTH(), YEAR() function for every entry in the table, which might take a long time and will cost a quite high amount of server resources if many orders are stored. You might consider changing it to this (working) approach:
if ($range === 'day')
return 'date_added BETWEEN "'.date("Y-m-d H:i:s",time()-(3600*24)).'" and "'.date("Y-m-d H:i:s").'"';
if ($range === 'week')
return 'date_added BETWEEN "'.date("Y-m-d H:i:s",time()-(3600*24*7)).'" and "'.date("Y-m-d H:i:s").'"';
if ($range === 'month')
return 'date_added BETWEEN "'.date("Y-m-d H:i:s",time()-(3600*24*31)).'" and "'.date("Y-m-d H:i:s").'"';
if ($range === 'year')
return 'date_added BETWEEN "'.date("Y-m-d H:i:s",time()-(3600*24*356)).'" and "'.date("Y-m-d H:i:s").'"';
return $range;
}
In big tables this will be much faster 😉
Greetings
Darkmaterial