From 4322abb39fe8672ba0179e9a460a73ae65fdfffc Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 22 Jul 2008 10:32:25 +0000 Subject: - 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 --- include/filter.inc.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'include/filter.inc.php') diff --git a/include/filter.inc.php b/include/filter.inc.php index b77ddca98..d63515265 100644 --- a/include/filter.inc.php +++ b/include/filter.inc.php @@ -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'); -- cgit v1.2.3