Update the APCu global code to use internal API and conventions better as suggested in comments for ea01f20da9

remotes/angel/1.11.x
Yannick Warnier 8 years ago
parent 4a31f519a1
commit 0cadaa026f
  1. 2
      main/inc/global.inc.php
  2. 13
      main/inc/lib/api.lib.php
  3. 14
      main/inc/lib/banner.lib.php
  4. 6
      main/inc/lib/message.lib.php
  5. 8
      main/inc/lib/tracking.lib.php
  6. 12
      main/inc/lib/usermanager.lib.php

@ -195,7 +195,7 @@ if (!empty($_configuration['multiple_access_urls'])) {
// Check if APCu is available. If so, store the value in $_configuration
if (extension_loaded('apcu')) {
$_configuration['apc'] = true;
$_configuration['apcPrefix'] = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
$_configuration['apc_prefix'] = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
}
$charset = 'UTF-8';

@ -1456,15 +1456,14 @@ function api_get_user_info(
$loadOnlyVisibleExtraData = false,
$loadAvatars = true
) {
global $_configuration;
$apcVar = null;
$user = false;
$cacheAvailable = api_get_configuration_value('apc');
if (empty($user_id)) {
$userFromSession = Session::read('_user');
if (isset($userFromSession)) {
if (!empty($_configuration['apc'])) {
$apcVar = $_configuration['apcPrefix'] . 'userinfo_' . $userFromSession['user_id'];
if (!empty($cacheAvailable)) {
$apcVar = api_get_configuration_value('apc_prefix') . 'userinfo_' . $userFromSession['user_id'];
if (apcu_exists($apcVar)) {
$user = apcu_fetch($apcVar);
} else {
@ -1485,8 +1484,8 @@ function api_get_user_info(
$user_id = intval($user_id);
// Re-use user information if not stale and already stored in APCu
if (!empty($_configuration['apc'])) {
$apcVar = $_configuration['apcPrefix'].'userinfo_'.$user_id;
if (!empty($cacheAvailable)) {
$apcVar = api_get_configuration_value('apc_prefix') . 'userinfo_' . $user_id;
if (apcu_exists($apcVar)) {
$user = apcu_fetch($apcVar);
@ -1527,7 +1526,7 @@ function api_get_user_info(
}
$user = _api_format_user($result_array, $showPassword, $loadAvatars);
}
if (!empty($_configuration['apc'])) {
if (!empty($cacheAvailable)) {
apcu_store($apcVar, $user, 60);
}

@ -727,10 +727,10 @@ function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
*/
function getOnlineUsersCount()
{
global $_configuration;
$number = 0;
if (!empty($_configuration['apc'])) {
$apcVar = $_configuration['apcPrefix'].'my_campus_whoisonline_count_simple';
$cacheAvailable = api_get_configuration_value('apc');
if (!empty($cacheAvailable)) {
$apcVar = api_get_configuration_value('apc_refix') . 'my_campus_whoisonline_count_simple';
if (apcu_exists($apcVar)) {
$number = apcu_fetch($apcVar);
} else {
@ -752,13 +752,11 @@ function getOnlineUsersCount()
*/
function getOnlineUsersInCourseCount($userId, $_course)
{
global $_configuration;
$cacheAvailable = api_get_configuration_value('apc');
$numberOnlineInCourse = 0;
if (!empty($_course['id'])) {
if (!empty($_configuration['apc'])) {
global $_configuration;
$apcVar = $_configuration['apcPrefix'].'my_campus_whoisonline_count_simple_'.$_course['id'];
$apc = apcu_cache_info(true);
if (!empty($cacheAvailable)) {
$apcVar = api_get_configuration_value('apc_refix') . 'my_campus_whoisonline_count_simple_' . $_course['id'];
if (apcu_exists($apcVar)) {
$numberOnlineInCourse = apcu_fetch($apcVar);
} else {

@ -27,9 +27,9 @@ class MessageManager
static $count;
if (!isset($count)) {
global $_configuration;
if (!empty($_configuration['apc'])) {
$var = $_configuration['apcPrefix'].'social_messages_unread_u_'.$userId;
$cacheAvailable = api_get_configuration_value('apc');
if (!empty($cacheAvailable)) {
$var = api_get_configuration_value('apc_refix') . 'social_messages_unread_u_' . $userId;
if (apcu_exists($var)) {
$count = apcu_fetch($var);
} else {

@ -1686,13 +1686,13 @@ class Tracking
$month_filter";
//This query can be very slow (several seconds on an indexed table
// with 14M rows). As such, we'll try to use APCU if it is
// with 14M rows). As such, we'll try to use APCu if it is
// available to store the resulting value for a few seconds
global $_configuration;
if (!empty($_configuration['apc'])) {
$cacheAvailable = api_get_configuration_value('apc');
if (!empty($cacheAvailable)) {
$apc = apcu_cache_info(true);
$apc_end = $apc['start_time'] + $apc['ttl'];
$apc_var = $_configuration['apcPrefix'].'course_access_'.$courseId.'_'.$session_id.'_'.strtotime($roundedStart).'_'.strtotime($roundedStop);
$apc_var = api_get_configuration_value('apc_refix') . 'course_access_' . $courseId . '_' . $session_id . '_' . strtotime($roundedStart) . '_' . strtotime($roundedStop);
if (apcu_exists($apc_var) && (time() < $apc_end) &&
apcu_fetch($apc_var) > 0
) {

@ -755,9 +755,9 @@ class UserManager
api_get_utc_datetime(),
$user_id_manager
);
global $_configuration;
if (!empty($_configuration['apc'])) {
$apcVar = $_configuration['apcPrefix'] . 'userinfo_' . $user_id;
$cacheAvailable = api_get_configuration_value('apc');
if (!empty($cacheAvailable)) {
$apcVar = api_get_configuration_value('apc_prefix') . 'userinfo_' . $user_id;
if (apcu_exists($apcVar)) {
apcu_delete($apcVar);
}
@ -1082,9 +1082,9 @@ class UserManager
$hook->notifyUpdateUser(HOOK_EVENT_TYPE_POST);
}
global $_configuration;
if (!empty($_configuration['apc'])) {
$apcVar = $_configuration['apcPrefix'] . 'userinfo_' . $user_id;
$cacheAvailable = api_get_configuration_value('apc');
if (!empty($cacheAvailable)) {
$apcVar = api_get_configuration_value('apc_prefix') . 'userinfo_' . $user_id;
if (apcu_exists($apcVar)) {
apcu_delete($apcVar);
}

Loading…
Cancel
Save