diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-07-22 10:32:25 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-07-22 10:32:25 +0000 |
commit | 4322abb39fe8672ba0179e9a460a73ae65fdfffc (patch) | |
tree | a88acf5edd7291cb926c60ecf796b5e7b3f8e0f4 /include | |
parent | ecc5ee46fa3caf6622a4cccae3870a950fb0a969 (diff) |
- 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
Diffstat (limited to 'include')
-rw-r--r-- | include/filter.inc.php | 26 | ||||
-rw-r--r-- | include/functions_filter.inc.php | 13 | ||||
-rw-r--r-- | include/functions_user.inc.php | 21 |
3 files changed, 22 insertions, 38 deletions
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'); diff --git a/include/functions_filter.inc.php b/include/functions_filter.inc.php index 24efb0994..d121a214e 100644 --- a/include/functions_filter.inc.php +++ b/include/functions_filter.inc.php @@ -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 diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index d9e9332ad..f60a7fe77 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -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; |