From 554bca8393e805ad365d5aeaf71b0d5ae77068b4 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 14 Jul 2016 14:47:26 +0200 Subject: [PATCH] send page-generation- and session-restore-time via json response not as dom fragment --- api/src/Etemplate.php | 6 ------ api/src/Framework.php | 27 +++++++++++++++++++++++---- api/src/Json/Response.php | 6 ++++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/api/src/Etemplate.php b/api/src/Etemplate.php index 4a76c4f87a..2b611d9ad8 100644 --- a/api/src/Etemplate.php +++ b/api/src/Etemplate.php @@ -231,12 +231,6 @@ class Etemplate extends Etemplate\Widget\Template { $content = '
'."\n". ''; - // add server-side page-generation times - if($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time']) - { - $vars = $GLOBALS['egw']->framework->_get_footer(); - $content .= "\n".$vars['page_generation_time']; - } $GLOBALS['egw']->framework->response->generic("data", array($content)); $GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra()); Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) diff --git a/api/src/Framework.php b/api/src/Framework.php index 8fe679fec5..47d583fb2e 100644 --- a/api/src/Framework.php +++ b/api/src/Framework.php @@ -348,6 +348,23 @@ abstract class Framework extends Framework\Extra (new Framework\Login($this))->deny_screen(); } + /** + * Calculate page-generation- and session-restore times + * + * @return array values for keys 'page_generation_time' and 'session_restore_time', if display is an + */ + public static function get_page_generation_time() + { + $times = array( + 'page_generation_time' => sprintf('%4.2lf', microtime(true) - $GLOBALS['egw_info']['flags']['page_start_time']), + ); + if ($GLOBALS['egw_info']['flags']['session_restore_time']) + { + $times['session_restore_time'] = sprintf('%4.2lf', $GLOBALS['egw_info']['flags']['session_restore_time']); + } + return $times; + } + /** * Get footer as array to eg. set as vars for a template (from idots' head.inc.php) * @@ -362,13 +379,15 @@ abstract class Framework extends Framework\Extra $var['page_generation_time'] = ''; if($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time']) { - $totaltime = sprintf('%4.2lf',microtime(true) - $GLOBALS['egw_info']['flags']['page_start_time']); + $times = self::get_page_generation_time(); - $var['page_generation_time'] = '
'.lang('Page was generated in %1 seconds',$totaltime); - if ($GLOBALS['egw_info']['flags']['session_restore_time']) + $var['page_generation_time'] = '
'. + lang('Page was generated in %1 seconds', $times['page_generation_time']); + + if (isset($times['session_restore_time'])) { $var['page_generation_time'] .= ' '.lang('(session restored in %1 seconds)', - sprintf('%4.2lf',$GLOBALS['egw_info']['flags']['session_restore_time'])); + $times['session_restore_time']); } $var['page_generation_time'] .= '
'; } diff --git a/api/src/Json/Response.php b/api/src/Json/Response.php index 94055dc5b1..60d8e31162 100644 --- a/api/src/Json/Response.php +++ b/api/src/Json/Response.php @@ -223,8 +223,10 @@ class Response extends Msg { $inst = self::get(); - /* Wrap the result array into a parent "response" Object */ - $res = array('response' => $inst->responseArray); + // Wrap the result array into a parent "response" Object + $res = array( + 'response' => $inst->responseArray, + )+Api\Framework::get_page_generation_time(); return self::json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); }