[geeklog-hg] geeklog: If cache enabled Topic array is now stored as a cache f...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Fri Jun 21 15:32:33 EDT 2013
changeset 9110:3ddc8f6f9196
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/3ddc8f6f9196
user: Tom <websitemaster at cogeco.net>
date: Fri Jun 21 15:32:22 2013 -0400
description:
If cache enabled Topic array is now stored as a cache file instead of in the session or vars table
diffstat:
public_html/lib-common.php | 62 ++++++++++++++++++++++++++++++---------------
system/lib-topic.php | 26 +++++++++++-------
2 files changed, 57 insertions(+), 31 deletions(-)
diffs (115 lines):
diff -r 743787913526 -r 3ddc8f6f9196 public_html/lib-common.php
--- a/public_html/lib-common.php Fri Jun 21 13:56:57 2013 -0400
+++ b/public_html/lib-common.php Fri Jun 21 15:32:22 2013 -0400
@@ -498,31 +498,51 @@
*
*/
-// Figure out if we need to update topic tree or retrieve it from the session
+// Figure out if we need to update topic tree or retrieve it from the session/cache
+// For anonymous users topic tree data can be shared
+// Retrieve when last topic update happened
$last_topic_update = DB_getItem($_TABLES['vars'], 'value', "name='last_topic_update'");
-if (COM_isAnonUser()) { // For Anon users data stored in vars table since all anon users can use the same topic tree
- if ($last_topic_update != DB_getItem($_TABLES['vars'], 'value', "name='anon_topic_tree_date'")) {
- // Tree has changed for anonymous users so rebuild tree
- $_TOPICS = TOPIC_buildTree(TOPIC_ROOT, true);
-
- // Save updated topic tree and date
- DB_query("UPDATE {$_TABLES['vars']} SET value='$last_topic_update' WHERE name='anon_topic_tree_date'");
- DB_query("UPDATE {$_TABLES['vars']} SET value='" . serialize($_TOPICS) . "' WHERE name='anon_topic_tree'");
+// Figure out how old stored topic tree is
+if ($_CONF['cache_templates']) {
+ if (COM_isAnonUser()) {
+ $uid = 1;
} else {
- $_TOPICS = unserialize(DB_getItem($_TABLES['vars'], 'value', "name='anon_topic_tree'"));
- }
+ $uid = $_USER['uid'];
+ }
+ $cacheInstance = 'topic_tree__' . CACHE_security_hash() . '__' . $uid;
+ $topic_tree_date = date("Y-m-d H:i:s", CACHE_get_instance_update($cacheInstance, true));
} else {
- if ($last_topic_update != SESS_getVariable('topic_tree_date')) {
- // Tree has changed for current logged in user so rebuild tree
- $_TOPICS = TOPIC_buildTree(TOPIC_ROOT, true);
-
- // Save updated topic tree and date
- SESS_setVariable('topic_tree_date', $last_topic_update);
- SESS_setVariable('topic_tree', serialize($_TOPICS));
+ if (COM_isAnonUser()) {
+ $topic_tree_date = DB_getItem($_TABLES['vars'], 'value', "name='anon_topic_tree_date'");
} else {
- $_TOPICS = unserialize(SESS_getVariable('topic_tree'));
- }
-}
+ $topic_tree_date = SESS_getVariable('topic_tree_date');
+ }
+}
+// See if Topic Tree has changed for users, if so rebuild tree
+if ($last_topic_update > $topic_tree_date) {
+ $_TOPICS = TOPIC_buildTree(TOPIC_ROOT, true);
+
+ // Save updated topic tree and date
+ if ($_CONF['cache_templates']) {
+ CACHE_create_instance($cacheInstance, serialize($_TOPICS), true);
+ } else {
+ if (COM_isAnonUser()) {
+ DB_query("UPDATE {$_TABLES['vars']} SET value='$last_topic_update' WHERE name='anon_topic_tree_date'");
+ DB_query("UPDATE {$_TABLES['vars']} SET value='" . serialize($_TOPICS) . "' WHERE name='anon_topic_tree'");
+ } else {
+ SESS_setVariable('topic_tree_date', $last_topic_update);
+ SESS_setVariable('topic_tree', serialize($_TOPICS));
+ }
+ }
+} else {
+ if ($_CONF['cache_templates']) {
+ $serialized_topic_tree = CACHE_check_instance($cacheInstance, true);
+ } else {
+ $serialized_topic_tree = DB_getItem($_TABLES['vars'], 'value', "name='anon_topic_tree'");
+ }
+ $_TOPICS = unserialize($serialized_topic_tree);
+}
+
// Figure out if we need to update article feeds. Check last article date punlished in feed
$sql = "SELECT date FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() AND perm_anon > 0 ORDER BY date DESC LIMIT 1";
$result = DB_query($sql);
diff -r 743787913526 -r 3ddc8f6f9196 system/lib-topic.php
--- a/system/lib-topic.php Fri Jun 21 13:56:57 2013 -0400
+++ b/system/lib-topic.php Fri Jun 21 15:32:22 2013 -0400
@@ -1837,19 +1837,25 @@
*/
function plugin_user_changed_topic($uid)
{
+ global $_CONF;
+
// Wipe out user's session variable for last_topic_update (if it exists) since their
// security may have changed and the topic tree should be updated again
-
- // See if user (other than anonymous) has a session
- if ($uid > 1) {
- $session_id = SESS_getSessionIdFromUserId($uid);
-
- if (!empty($session_id)) {
- SESS_setVariable('topic_tree_date', '', $session_id);
+ if ($_CONF['cache_templates']) {
+ $cacheInstance = 'topic_tree__' . CACHE_security_hash() . '__' . $uid;
+ CACHE_remove_instance($cacheInstance);
+ } else {
+ // See if user (other than anonymous) has a session
+ if ($uid > 1) {
+ $session_id = SESS_getSessionIdFromUserId($uid);
+
+ if (!empty($session_id)) {
+ SESS_setVariable('topic_tree_date', '', $session_id);
+ }
+ } else {
+ // Delete topic tree array date in vars table
+ DB_query("UPDATE {$_TABLES['vars']} SET value='' WHERE name='anon_topic_tree_date'");
}
- } else {
- // Delete topic tree array date in vars table
- DB_query("UPDATE {$_TABLES['vars']} SET value='' WHERE name='anon_topic_tree_date'");
}
}
More information about the geeklog-cvs
mailing list