[geeklog-hg] geeklog: Sped up Geeklog by storing Topic tree as a session vari...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Wed Jun 19 20:37:11 EDT 2013
changeset 9106:60c03d473a2b
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/60c03d473a2b
user: Tom <websitemaster at cogeco.net>
date: Wed Jun 19 20:34:51 2013 -0400
description:
Sped up Geeklog by storing Topic tree as a session variable (feature request #0001626)
diffstat:
public_html/admin/topic.php | 6 +
public_html/lib-common.php | 28 +-
sql/mssql_tableanddata.php | 9 +-
sql/mysql_tableanddata.php | 7 +-
sql/pgsql_tableanddata.php | 5 +
sql/updates/mssql_2.0.0_to_2.0.1.php | 12 +
sql/updates/mysql_2.0.0_to_2.0.1.php | 12 +
sql/updates/pgsql_2.0.0_to_2.0.1.php | 12 +
system/lib-plugins.php | 5 +-
system/lib-sessions.php | 29 +-
system/lib-topic.php | 473 +++++++++++++++++++---------------
11 files changed, 378 insertions(+), 220 deletions(-)
diffs (truncated from 789 to 300 lines):
diff -r e25cee2e0424 -r 60c03d473a2b public_html/admin/topic.php
--- a/public_html/admin/topic.php Wed Jun 19 15:23:40 2013 -0400
+++ b/public_html/admin/topic.php Wed Jun 19 20:34:51 2013 -0400
@@ -523,6 +523,9 @@
PLG_itemSaved($tid, 'topic');
}
+ // Update date of change to a topic
+ TOPIC_updateLastTopicUpdate();
+
// update feed(s) and Older Stories block
COM_rdfUpToDateCheck('article', $tid);
COM_olderStuff();
@@ -885,6 +888,9 @@
// Update Topics Array to reflect any changes since not sure what is called after
$_TOPICS = TOPIC_buildTree(TOPIC_ROOT, true);
+ // Update date of change to a topic
+ TOPIC_updateLastTopicUpdate();
+
// update feed(s) and Older Stories block
COM_rdfUpToDateCheck('article');
COM_olderStuff();
diff -r e25cee2e0424 -r 60c03d473a2b public_html/lib-common.php
--- a/public_html/lib-common.php Wed Jun 19 15:23:40 2013 -0400
+++ b/public_html/lib-common.php Wed Jun 19 20:34:51 2013 -0400
@@ -497,8 +497,32 @@
* @global array $_TOPICS
*
*/
-$_TOPICS = TOPIC_buildTree(TOPIC_ROOT, true);
-
+
+// Figure out if we need to update topic tree or retrieve it from the session
+$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'");
+ } else {
+ $_TOPICS = unserialize(DB_getItem($_TABLES['vars'], 'value', "name='anon_topic_tree'"));
+ }
+} 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));
+ } else {
+ $_TOPICS = unserialize(SESS_getVariable('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 e25cee2e0424 -r 60c03d473a2b sql/mssql_tableanddata.php
--- a/sql/mssql_tableanddata.php Wed Jun 19 15:23:40 2013 -0400
+++ b/sql/mssql_tableanddata.php Wed Jun 19 20:34:51 2013 -0400
@@ -263,7 +263,9 @@
[uid] [int] NOT NULL ,
[md5_sess_id] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[whos_online] [tinyint] NOT NULL,
- [topic] [varchar] (20) NOT NULL
+ [topic] [varchar] (20) NOT NULL,
+ [topic_tree_date] [datetime] NULL,
+ [topic_tree] [text] NULL
) ON [PRIMARY]
";
@@ -502,7 +504,7 @@
$_SQL[] = "
CREATE TABLE [dbo].[{$_TABLES['vars']}] (
[name] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
- [value] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
+ [value] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
";
@@ -1558,6 +1560,9 @@
$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('lastemailedstories','')";
$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_scheduled_run','')";
$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_article_publish','') ";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_topic_update','') ";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree_date','')";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree','')";
$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('database_version','0.0.0')";
$_SQL[] = "INSERT INTO {$_TABLES['trackbackcodes']} (code, name) VALUES (0,'Trackback Enabled')";
diff -r e25cee2e0424 -r 60c03d473a2b sql/mysql_tableanddata.php
--- a/sql/mysql_tableanddata.php Wed Jun 19 15:23:40 2013 -0400
+++ b/sql/mysql_tableanddata.php Wed Jun 19 20:34:51 2013 -0400
@@ -260,6 +260,8 @@
md5_sess_id varchar(128) default NULL,
whos_online tinyint(1) NOT NULL default '1',
topic varchar(20) NOT NULL default '',
+ topic_tree_date datetime DEFAULT NULL,
+ topic_tree text DEFAULT NULL,
PRIMARY KEY (sess_id),
KEY sess_id (sess_id),
KEY start_time (start_time),
@@ -543,7 +545,7 @@
$_SQL[] = "
CREATE TABLE {$_TABLES['vars']} (
name varchar(20) NOT NULL default '',
- value varchar(128) default NULL,
+ value text default NULL,
PRIMARY KEY (name)
) ENGINE=MyISAM
";
@@ -830,6 +832,9 @@
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('lastemailedstories','') ";
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_scheduled_run','') ";
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_article_publish','') ";
+$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_topic_update','') ";
+$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree_date','')";
+$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree','')";
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('database_version','0.0.0') ";
$_DATA[] = "INSERT INTO {$_TABLES['trackbackcodes']} (code, name) VALUES (0,'Trackback Enabled') ";
diff -r e25cee2e0424 -r 60c03d473a2b sql/pgsql_tableanddata.php
--- a/sql/pgsql_tableanddata.php Wed Jun 19 15:23:40 2013 -0400
+++ b/sql/pgsql_tableanddata.php Wed Jun 19 20:34:51 2013 -0400
@@ -259,6 +259,8 @@
md5_sess_id varchar(128) default NULL,
whos_online smallint NOT NULL default '1',
topic varchar(20) NOT NULL default '',
+ topic_tree_date timestamp DEFAULT NULL,
+ topic_tree text DEFAULT NULL,
PRIMARY KEY (sess_id)
);
CREATE INDEX {$_TABLES['sessions']}_start_time ON {$_TABLES['sessions']} (start_time);
@@ -848,6 +850,9 @@
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('lastemailedstories','') ";
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_scheduled_run','') ";
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_article_publish','') ";
+$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_topic_update','') ";
+$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree_date','')";
+$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree','')";
$_DATA[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('database_version','0.0.0') ";
$_DATA[] = "INSERT INTO {$_TABLES['trackbackcodes']} (code, name) VALUES (0,'Trackback Enabled') ";
diff -r e25cee2e0424 -r 60c03d473a2b sql/updates/mssql_2.0.0_to_2.0.1.php
--- a/sql/updates/mssql_2.0.0_to_2.0.1.php Wed Jun 19 15:23:40 2013 -0400
+++ b/sql/updates/mssql_2.0.0_to_2.0.1.php Wed Jun 19 20:34:51 2013 -0400
@@ -3,6 +3,18 @@
// Delete anonymous user comment settings since all 3 are now config options
$_SQL[] = "DELETE FROM {$_TABLES['usercomment']} WHERE uid = 1";
+// Update Session Table
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD topic_tree_date datetime DEFAULT NULL AFTER topic";
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD topic_tree text DEFAULT NULL AFTER topic_tree_date";
+
+// Alter Session table structure
+$_SQL[] = "ALTER TABLE {$_TABLES['vars']} CHANGE `value` `value` TEXT DEFAULT NULL";
+
+// New Geeklog variable for Topics
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_topic_update','')";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree_date','')";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree','')";
+
/**
* Add new config options
*
diff -r e25cee2e0424 -r 60c03d473a2b sql/updates/mysql_2.0.0_to_2.0.1.php
--- a/sql/updates/mysql_2.0.0_to_2.0.1.php Wed Jun 19 15:23:40 2013 -0400
+++ b/sql/updates/mysql_2.0.0_to_2.0.1.php Wed Jun 19 20:34:51 2013 -0400
@@ -3,6 +3,18 @@
// Delete anonymous user comment settings since all 3 are now config options
$_SQL[] = "DELETE FROM {$_TABLES['usercomment']} WHERE uid = 1";
+// Update Session Table
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD topic_tree_date datetime DEFAULT NULL AFTER topic";
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD topic_tree text DEFAULT NULL AFTER topic_tree_date";
+
+// Alter Session table structure
+$_SQL[] = "ALTER TABLE {$_TABLES['vars']} CHANGE `value` `value` TEXT DEFAULT NULL";
+
+// New Geeklog variable for Topics
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_topic_update','')";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree_date','')";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree','')";
+
/**
* Add new config options
*
diff -r e25cee2e0424 -r 60c03d473a2b sql/updates/pgsql_2.0.0_to_2.0.1.php
--- a/sql/updates/pgsql_2.0.0_to_2.0.1.php Wed Jun 19 15:23:40 2013 -0400
+++ b/sql/updates/pgsql_2.0.0_to_2.0.1.php Wed Jun 19 20:34:51 2013 -0400
@@ -3,6 +3,18 @@
// Delete anonymous user comment settings since all 3 are now config options
$_SQL[] = "DELETE FROM {$_TABLES['usercomment']} WHERE uid = 1";
+// Update Session Table
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD topic_tree_date datetime DEFAULT NULL AFTER topic";
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD topic_tree text DEFAULT NULL AFTER topic_tree_date";
+
+// Alter Session table structure
+$_SQL[] = "ALTER TABLE {$_TABLES['vars']} CHANGE `value` `value` TEXT DEFAULT NULL";
+
+// New Geeklog variable for Topics
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('last_topic_update','')";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree_date','')";
+$_SQL[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('anon_topic_tree','')";;
+
/**
* Add new config options
*
diff -r e25cee2e0424 -r 60c03d473a2b system/lib-plugins.php
--- a/system/lib-plugins.php Wed Jun 19 15:23:40 2013 -0400
+++ b/system/lib-plugins.php Wed Jun 19 20:34:51 2013 -0400
@@ -1274,7 +1274,9 @@
{
global $_PLUGINS;
- foreach ($_PLUGINS as $pi_name) {
+ $all_plugins = array_merge($_PLUGINS, array('topic'));
+
+ foreach ($all_plugins as $pi_name) {
$function = 'plugin_user_changed_' . $pi_name;
if (function_exists($function)) {
$function($uid);
@@ -1566,7 +1568,6 @@
}
// ensure that we're picking up the Core autotags
-
require_once $_CONF['path_system'] . 'lib-story.php';
require_once $_CONF['path_system'] . 'lib-user.php';
require_once $_CONF['path_system'] . 'lib-topic.php';
diff -r e25cee2e0424 -r 60c03d473a2b system/lib-sessions.php
--- a/system/lib-sessions.php Wed Jun 19 15:23:40 2013 -0400
+++ b/system/lib-sessions.php Wed Jun 19 20:34:51 2013 -0400
@@ -564,6 +564,28 @@
return $myrow;
}
+
+/**
+* Gets the Session ID from the User Id
+*
+* Returns the session id associated with the user if available.
+* This is not for anonymous users. If no match found, returns an empty string.
+*
+* @param int $uid User Id to retrieve session Id for
+* @return string Session ID
+*/
+function SESS_getSessionIdFromUserId($uid)
+{
+ global $_TABLES;
+
+ $retval = '';
+ if ($uid > 1) {
+ $retval = DB_getItem($_TABLES['sessions'], "sess_id", "uid = $uid");
+ }
+
+ return $retval;
+}
+
/**
* Retrieves a session variable from the db
*
@@ -593,14 +615,17 @@
*
* @param string $variable Variable name to update
* @param string $value Value of variable
+* @param string $session_id Session ID of variable to update (0 = current session)
* @return boolean always true for some reason
*
*/
-function SESS_setVariable($variable, $value)
+function SESS_setVariable($variable, $value, $session_id = 0)
{
global $_TABLES, $_CONF, $_USER;
- $session_id = $_USER['session_id'];
+ if ($session_id == 0) {
+ $session_id = $_USER['session_id'];
+ }
if ( $_CONF['cookie_ip'] == 1) { // $md5_based Indicates if sessid is MD5 hash
$sql = "UPDATE {$_TABLES['sessions']} SET $variable = '$value' WHERE (md5_sess_id = '$session_id')";
diff -r e25cee2e0424 -r 60c03d473a2b system/lib-topic.php
--- a/system/lib-topic.php Wed Jun 19 15:23:40 2013 -0400
+++ b/system/lib-topic.php Wed Jun 19 20:34:51 2013 -0400
@@ -62,7 +62,7 @@
owner_id ID of the owner of the topic
group_id ID of group topic belongs to
perm_owner Permissions the owner has
-perm_group Permissions the gorup has
+perm_group Permissions the group has
perm_members Permissions logged in members have
perm_anon Permissions anonymous users have
@@ -157,181 +157,6 @@
More information about the geeklog-cvs
mailing list