- add #user_cache.cache_update_time - useful for plugins or the filter when it is not possible/desirable to cache/calculate data specific to the user when pwg core does it; note that this opens the possibility to implement a data cache (file/shared mem/ etc...) for every user (for very large databases)

git-svn-id: http://piwigo.org/svn/trunk@2448 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2008-07-22 10:32:25 +00:00
parent ecc5ee46fa
commit 4322abb39f
5 changed files with 69 additions and 38 deletions

View file

@ -22,7 +22,6 @@
// +-----------------------------------------------------------------------+
// $filter['enabled']: Filter is enabled
// $filter['check_key']: Check key to valitade computed filter data
// $filter['recent_period']: Recent period used to computed filter data
// $filter['categories']: Computed data of filtered categories
// $filter['visible_categories']:
@ -34,7 +33,7 @@ if (!get_filter_page_value('cancel'))
if (isset($_GET['filter']))
{
$filter['matches'] = array();
$filter['enabled'] =
$filter['enabled'] =
preg_match('/^start-recent-(\d+)$/', $_GET['filter'], $filter['matches']) === 1;
}
else
@ -49,26 +48,33 @@ else
if ($filter['enabled'])
{
$filter_key = pwg_get_session_var('filter_check_key', array('user'=>0,'recent_period'=>-1, 'time'=>0, 'date'=> '') );
if (isset($filter['matches']))
{
$filter['recent_period'] = $filter['matches'][1];
}
else
{
$filter['recent_period'] = pwg_get_session_var('filter_recent_period', $user['recent_period']);
$filter['recent_period'] = $filter_key['recent_period']>0 ? $filter_key['recent_period'] : $user['recent_period'];
}
if (
// New filter
!pwg_get_session_var('filter_enabled', false) or
// Cache data updated
$user['need_update_done'] or
$filter_key['time'] <= $user['cache_update_time'] or
// Date, period, user are changed
(pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
$filter_key['user'] != $user['id'] or
$filter_key['recent_period'] != $filter['recent_period'] or
$filter_key['date'] != date('Ymd')
)
{
// Need to compute dats
$filter['check_key'] = get_filter_check_key();
$filter_key = array(
'user'=>(int)$user['id'],'recent_period'=>(int)$filter['recent_period'], 'time'=>time(), 'date'=> date('Ymd')
);
$filter['categories'] = get_computed_categories($user, (int)$filter['recent_period']);
$filter['visible_categories'] = implode(',', array_keys($filter['categories']));
@ -103,22 +109,19 @@ WHERE ';
// Save filter data on session
pwg_set_session_var('filter_enabled', $filter['enabled']);
pwg_set_session_var('filter_check_key', $filter['check_key']);
pwg_set_session_var('filter_recent_period', $filter['recent_period']);
pwg_set_session_var('filter_check_key', $filter_key);
pwg_set_session_var('filter_categories', serialize($filter['categories']));
pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
pwg_set_session_var('filter_visible_images', $filter['visible_images']);
}
else
{
// Read only data
$filter['check_key'] = pwg_get_session_var('filter_check_key', '');
$filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
$filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
$filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
}
unset($filter_key);
if (get_filter_page_value('add_notes'))
{
$header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $filter['recent_period']);
@ -130,7 +133,6 @@ else
{
pwg_unset_session_var('filter_enabled');
pwg_unset_session_var('filter_check_key');
pwg_unset_session_var('filter_recent_period');
pwg_unset_session_var('filter_categories');
pwg_unset_session_var('filter_visible_categories');
pwg_unset_session_var('filter_visible_images');

View file

@ -22,19 +22,6 @@
// +-----------------------------------------------------------------------+
/**
* Get a check key for filtered data
* Check key are composed of elements witch force to compute data
*
* @param null
* @return strinf check_key
*/
function get_filter_check_key()
{
global $user, $filter;
return $user['id'].$filter['recent_period'].date('Ymd');
}
/**
* update data of categories with filtered values

View file

@ -299,6 +299,11 @@ SELECT ui.*, uc.*
or !is_bool($userdata['need_update'])
or $userdata['need_update'] == true)
{
$userdata['cache_update_time'] = time();
// Set need update are done
$userdata['need_update'] = false;
$userdata['forbidden_categories'] =
calculate_permissions($userdata['id'], $userdata['status']);
@ -320,12 +325,6 @@ SELECT DISTINCT(id)
update_user_cache_categories($userdata);
// Set need update are done
$userdata['need_update'] = false;
// Indicate update done
$userdata['need_update_done'] = true;
$query = '
SELECT COUNT(DISTINCT(image_id)) as total
FROM '.IMAGE_CATEGORY_TABLE.'
@ -343,20 +342,16 @@ DELETE FROM '.USER_CACHE_TABLE.'
$query = '
INSERT INTO '.USER_CACHE_TABLE.'
(user_id, need_update, forbidden_categories, nb_total_images,
(user_id, need_update, cache_update_time, forbidden_categories, nb_total_images,
image_access_type, image_access_list)
VALUES
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\''
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\','
.$userdata['cache_update_time'].',\''
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
.$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")
;';
pwg_query($query);
}
else
{
// Indicate update not done
$userdata['need_update_done'] = false;
}
}
return $userdata;

View file

@ -0,0 +1,46 @@
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based picture gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}
$upgrade_description = 'Add #user_cache.cache_update_time';
// +-----------------------------------------------------------------------+
// | Upgrade content |
// +-----------------------------------------------------------------------+
$query = '
ALTER TABLE '.USER_CACHE_TABLE.' ADD COLUMN `cache_update_time` INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER need_update';
pwg_query($query);
echo
"\n"
.'"'.$upgrade_description.'"'.' ended'
."\n"
;
?>

View file

@ -320,6 +320,7 @@ DROP TABLE IF EXISTS `piwigo_user_cache`;
CREATE TABLE `piwigo_user_cache` (
`user_id` smallint(5) NOT NULL default '0',
`need_update` enum('true','false') NOT NULL default 'true',
`cache_update_time` integer unsigned NOT NULL default 0,
`forbidden_categories` mediumtext,
`nb_total_images` mediumint(8) unsigned default NULL,
`image_access_type` enum('NOT IN','IN') NOT NULL default 'NOT IN',