From b36c02f320e1d3250bbd5784d05d6044f70a19c8 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 9 Mar 2006 18:32:50 +0000 Subject: [PATCH] - fix cookie shortening - let the acm handle the module cache - call $cache->save() after destroying data if necessary git-svn-id: file:///svn/phpbb/trunk@5612 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/cron.php | 2 +- phpBB/includes/acm/acm_file.php | 3 ++ phpBB/includes/acm/acm_main.php | 5 ++-- phpBB/includes/acp/acp_modules.php | 7 ++--- phpBB/includes/db/dbal.php | 1 - phpBB/includes/functions.php | 45 +++++++++++++++++++++-------- phpBB/includes/functions_module.php | 35 +++++----------------- 7 files changed, 48 insertions(+), 50 deletions(-) diff --git a/phpBB/cron.php b/phpBB/cron.php index 15564e1f5c..4a23143a2d 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -24,7 +24,7 @@ $use_shutdown_function = (@function_exists('register_shutdown_function')) ? true * Run cron-like action * Real cron-based layer will be introduced in 3.2 * -* @todo: check gc-intervals here too (important!) +* @todo check gc-intervals here too (important!) */ switch ($cron_type) { diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php index fa430b9247..3a11f5b6d6 100644 --- a/phpBB/includes/acm/acm_file.php +++ b/phpBB/includes/acm/acm_file.php @@ -191,6 +191,9 @@ class acm $this->is_modified = true; unset($this->vars[$var_name]); unset($this->var_expires[$var_name]); + + // We save here to let the following cache hits succeed + $this->save(); } } diff --git a/phpBB/includes/acm/acm_main.php b/phpBB/includes/acm/acm_main.php index 679998938f..3f6e413f20 100644 --- a/phpBB/includes/acm/acm_main.php +++ b/phpBB/includes/acm/acm_main.php @@ -301,7 +301,7 @@ class cache extends acm foreach ($parsed_items as $key => $parsed_array) { - $parsed_array = $this->get('_' . $key . '_cfg'); + $parsed_array = $this->get('_cfg_' . $key); if (!$parsed_array) { @@ -327,14 +327,13 @@ class cache extends acm $parsed_array = parse_cfg_file($filename); $parsed_array['filetime'] = @filemtime($filename); - $this->put('_' . $key . '_cfg', $parsed_array); + $this->put('_cfg_' . $key, $parsed_array); } $parsed_items[$key] = $parsed_array; } return $parsed_items; } - } ?> \ No newline at end of file diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index fab7731567..927fed7502 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -749,15 +749,12 @@ class acp_modules */ function remove_cache_file() { - global $phpbb_root_path, $phpEx; + global $cache; // Sanitise for future path use, it's escaped as appropriate for queries $p_class = str_replace(array('.', '/', '\\'), '', basename($this->module_class)); - if (file_exists($phpbb_root_path . 'cache/' . $p_class . '_modules.' . $phpEx)) - { - @unlink($phpbb_root_path . 'cache/' . $p_class . '_modules.' . $phpEx); - } + $cache->destroy('_modules_' . $p_class); } /** diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 4de7f2d5ee..fbd699eadf 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -250,7 +250,6 @@ class dbal /** * Explain queries - * @child _sql_report */ function sql_report($mode, $query = '') { diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d474505eff..092c527902 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -112,7 +112,6 @@ function set_config($config_name, $config_value, $is_dynamic = false) if (!$is_dynamic) { $cache->destroy('config'); - $cache->save(); } } @@ -691,25 +690,47 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0) $post_time = ($post_time) ? $post_time : time(); $tracking['t'][$topic_id36] = base_convert($post_time - $config['board_startdate'], 10, 36); - // If the cookie grows larger than 5000 characters we will remove the smallest value - if (isset($_COOKIE[$config['cookie_name'] . '_track']) && strlen($_COOKIE[$config['cookie_name'] . '_track']) > 5000) + // If the cookie grows larger than 10000 characters we will remove the smallest value + // This can result in old topics being unread - but most of the time it should be accurate... + if (isset($_COOKIE[$config['cookie_name'] . '_track']) && strlen($_COOKIE[$config['cookie_name'] . '_track']) > 10000) { -// echo 'Cookie grown too large' . print_r($tracking, true); + //echo 'Cookie grown too large' . print_r($tracking, true); - $min_value = min($tracking['t']); - $m_tkey = array_search($min_value, $t_ary); - unset($tracking['t'][$m_tkey]); - + // We get the ten most minimum stored time offsets and its associated topic ids + $time_keys = array(); + for ($i = 0; $i < 10 && sizeof($tracking['t']); $i++) + { + $min_value = min($tracking['t']); + $m_tkey = array_search($min_value, $tracking['t']); + unset($tracking['t'][$m_tkey]); + + $time_keys[$m_tkey] = $min_value; + } + + // Now remove the topic ids from the array... foreach ($tracking['tf'] as $f_id => $topic_id_ary) { - if (in_array($m_tkey, array_keys($topic_id_ary))) + foreach ($time_keys as $m_tkey => $min_value) { - unset($tracking['tf'][$f_id][$m_tkey]); - break; + if (isset($topic_id_ary[$m_tkey])) + { + $tracking['f'][$f_id] = $min_value; + unset($tracking['tf'][$f_id][$m_tkey]); + } } } + + if ($user->data['is_registered']) + { + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . intval(base_convert(max($time_keys) + $config['board_startdate'], 36, 10)) . " WHERE user_id = {$user->data['user_id']}"); + } + else + { + $tracking['l'] = max($time_keys); + } + } - + $user->set_cookie('track', serialize($tracking), time() + 31536000); } diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 6e8fc7b2c8..b7af1c4b17 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -10,6 +10,7 @@ /** * Class handling all types of 'plugins' (a future term) +* @package phpBB3 */ class p_master { @@ -44,31 +45,19 @@ class p_master */ function list_modules($p_class) { - global $auth, $db, $user; + global $auth, $db, $user, $cache; global $config, $phpbb_root_path, $phpEx; - $get_cache_data = true; - - // Empty cached contents - $this->module_cache = array(); - // Sanitise for future path use, it's escaped as appropriate for queries $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); - - if (file_exists($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx)) - { - include($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx); - $get_cache_data = false; - } - if ($get_cache_data) + // Get cached modules + if (!($this->module_cache = $cache->get('_modules_' . $this->p_class))) { - global $cache; - // Get modules $sql = 'SELECT * FROM ' . MODULES_TABLE . " - WHERE module_class = '" . $db->sql_escape($p_class) . "' + WHERE module_class = '" . $db->sql_escape($this->p_class) . "' ORDER BY left_id ASC"; $result = $db->sql_query($sql); @@ -77,7 +66,7 @@ class p_master { $rows[$row['module_id']] = $row; } - $db->sql_freeresult($result); + $db->sql_freeresult($result); $this->module_cache = array(); foreach ($rows as $module_id => $row) @@ -87,17 +76,7 @@ class p_master } unset($rows); - $file = 'module_cache=' . $cache->format_array($this->module_cache) . "; ?>"; - - if ($fp = @fopen($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx, 'wb')) - { - @flock($fp, LOCK_EX); - fwrite($fp, $file); - @flock($fp, LOCK_UN); - fclose($fp); - } - - unset($file); + $cache->put('_modules_' . $this->p_class, $this->module_cache); } // We "could" build a true tree with this function - maybe mod authors want to use this...