class EntityPagerAdvice in Entity Pager 7
Class EntityPagerAdvice.
Provides a central and compact section of code where all performance advice logic and messages are handled.
Hierarchy
- class \EntityPager
- class \EntityPagerSetup
- class \EntityPagerAdvice
- class \EntityPagerSetup
Expanded class hierarchy of EntityPagerAdvice
File
- includes/
EntityPagerAdvice.inc, line 14 - A class to manage advice when using the Entity Pager module.
View source
class EntityPagerAdvice extends EntityPagerSetup {
/**
* Check performance.
*
* See if the option in the View is set to set to log performance.
* see: View > Format > Settings > Log performance suggestions.
*
* @return bool
* True mean check performance, false mean do not check performance.
*/
private function checkPerformance() {
$check_performance = FALSE;
// Get Views settings.
$settings = $this
->getSettings($this
->getView());
if ($settings['next_prev']['log_performance']) {
$check_performance = TRUE;
}
return $check_performance;
}
/**
* Get Cache status of View.
*
* A system state function on whether Views caching is configured on the View.
*
* @return bool
* True or false on whether views chaching is used.
*/
private function viewsCachingUsed() {
$view = $this
->getView();
$cache_value = $view->query->pager->display->handler->default_display->display->display_options['cache']['type'];
$cache_result = TRUE;
if ($cache_value == 'none') {
$cache_result = FALSE;
}
return $cache_result;
}
/**
* Run advice logic.
*
* Run the logic that manages performance advice.
*
* @param string $advice_type
* The type of advice.
* @param string $issue
* The specific issue.
*/
protected function runAdviceLogic($advice_type, $issue) {
if ($this
->checkPerformance()) {
// Log performance suggestions.
if ($advice_type == 'quantity') {
// Coding note: ideally nested 'if' statements should be avoided,
// but the whole purpose of this little logic method is to sort
// the logic in one manageable place. The if statements are simple
// (single purpose) meaning they are easy to work down logically.
if ($this
->getViewResultCount() > 500) {
if ($this
->viewsCachingUsed()) {
// Do nothing.
}
else {
$this
->logAdvice($advice_type, $issue);
}
}
}
else {
$this
->logAdvice($advice_type, $issue);
}
}
}
/**
* Log advice.
*
* Create a Performance Message and log it watchdog.
*
* @param string $advice_type
* The type of advice.
* @param string $issue
* The specific issue.
*/
private function logAdvice($advice_type, $issue) {
$view = $this
->getView();
switch ($advice_type) {
case 'no-records':
watchdog('entity_pager', "Performance Advice: in the View ('@view_name'),\n the issue ('@reason'), means you are needlessly attempting to\n displaying an empty Entity Pager block on this page.\n To ignore this advice, you can turn this alert off at:\n @view_name view > Format > Settings > Log performance\n suggestions.", array(
'@view_name' => $view->human_name,
'@reason' => $issue,
), WATCHDOG_INFO);
break;
case 'quantity':
watchdog('entity_pager', "Performance Advice: in the View ('@view_name'),\n the issue ('@reason'). At the moment there are 500+ records in\n your pager. The Entity Pager module is constructed to be fast\n keeping processing to a minimum, that said, it might still be a\n good idea to cache the Views Query Result see:\n @view_name view > Other > Caching. (Note: do not cache the\n Rendered output). To ignore this advice, you can turn this\n alert off at: @view_name view > Format > Settings >\n Log performance suggestions.", array(
'@view_name' => $view->human_name,
'@reason' => $issue,
), WATCHDOG_INFO);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityPager:: |
protected | property | ||
EntityPager:: |
public | function | Get Default value. | |
EntityPager:: |
public | function | Set the default values for Entity Pager. | |
EntityPagerAdvice:: |
private | function | Check performance. | |
EntityPagerAdvice:: |
private | function | Log advice. | |
EntityPagerAdvice:: |
protected | function | Run advice logic. | |
EntityPagerAdvice:: |
private | function | Get Cache status of View. | |
EntityPagerSetup:: |
protected | property | ||
EntityPagerSetup:: |
protected | property | ||
EntityPagerSetup:: |
protected | property | ||
EntityPagerSetup:: |
protected | property | ||
EntityPagerSetup:: |
protected | function | Establish Entity. | |
EntityPagerSetup:: |
protected | function | Establish the Entity Info from the View. | |
EntityPagerSetup:: |
public | function | Get All Title. | |
EntityPagerSetup:: |
public | function | Get All URL. | |
EntityPagerSetup:: |
public | function | Get result count word. | |
EntityPagerSetup:: |
public | function | Get Entity. | |
EntityPagerSetup:: |
public | function | Get Entity Information. | |
EntityPagerSetup:: |
protected | function | Get Entity Keys. | |
EntityPagerSetup:: |
protected | function | Generic 'Getter' for fields. | |
EntityPagerSetup:: |
public | function | Get Fields. | |
EntityPagerSetup:: |
protected | function | Get ID Field Name. | |
EntityPagerSetup:: |
public | function | Get Views Settings. | |
EntityPagerSetup:: |
public | function | Get View. | |
EntityPagerSetup:: |
public | function | Get View Result. | |
EntityPagerSetup:: |
public | function | Get View result count. | |
EntityPagerSetup:: |
public | function | Set All Title. | |
EntityPagerSetup:: |
public | function | Set Link All Url. | |
EntityPagerSetup:: |
public | function | Set Entity. | |
EntityPagerSetup:: |
protected | function | Set Entity Information. | |
EntityPagerSetup:: |
protected | function | Generic 'Setter' for fields. | |
EntityPagerSetup:: |
protected | function | Set Field Name of ID field. | |
EntityPagerSetup:: |
public | function | Set View. | |
EntityPagerSetup:: |
public | function |
Setup Entity Pager with minimum values to work with. Overrides EntityPager:: |