Split chatsitevisitor table into chatsitevisitor and visitedpage

This commit is contained in:
Dmitriy Simushev 2011-11-22 21:57:25 +00:00
parent 856123de48
commit 12b0883686
4 changed files with 45 additions and 27 deletions

View File

@ -119,7 +119,6 @@ $dbtables = array(
"firsttime" => "datetime NOT NULL DEFAULT 0", "firsttime" => "datetime NOT NULL DEFAULT 0",
"lasttime" => "datetime NOT NULL DEFAULT 0", "lasttime" => "datetime NOT NULL DEFAULT 0",
"entry" => "text NOT NULL", "entry" => "text NOT NULL",
"path" => "text NOT NULL",
"details" => "text NOT NULL", "details" => "text NOT NULL",
"invited" => "tinyint(1) NOT NULL DEFAULT 0", "invited" => "tinyint(1) NOT NULL DEFAULT 0",
"invitationtime" => "datetime", "invitationtime" => "datetime",
@ -128,6 +127,13 @@ $dbtables = array(
"chats" => "INT NOT NULL DEFAULT 0", "chats" => "INT NOT NULL DEFAULT 0",
"threadid" => "INT references ${mysqlprefix}chatthread(threadid) on delete set null" "threadid" => "INT references ${mysqlprefix}chatthread(threadid) on delete set null"
), ),
"${mysqlprefix}visitedpage" => array(
"pageid" => "INT NOT NULL auto_increment PRIMARY KEY",
"address" => "varchar(1024)",
"visittime" => "datetime NOT NULL DEFAULT 0",
"visitorid" => "INT",
),
); );
$dbtables_indexes = array( $dbtables_indexes = array(
@ -136,6 +142,9 @@ $dbtables_indexes = array(
), ),
"${mysqlprefix}chatsitevisitor" => array( "${mysqlprefix}chatsitevisitor" => array(
"threadid" => "threadid" "threadid" => "threadid"
),
"${mysqlprefix}visitedpage" => array(
"visitorid" => "visitorid"
) )
); );
@ -150,6 +159,7 @@ $dbtables_can_update = array(
"${mysqlprefix}chatgroupoperator" => array(), "${mysqlprefix}chatgroupoperator" => array(),
"${mysqlprefix}chatresponses" => array(), "${mysqlprefix}chatresponses" => array(),
"${mysqlprefix}chatsitevisitor" => array(), "${mysqlprefix}chatsitevisitor" => array(),
"${mysqlprefix}visitedpage" => array(),
); );
function show_install_err($text) function show_install_err($text)

View File

@ -168,6 +168,11 @@ if ($act == "silentcreateall") {
if ($res && mysql_num_rows($res) == 0) { if ($res && mysql_num_rows($res) == 0) {
runsql("ALTER TABLE ${mysqlprefix}chatsitevisitor ADD INDEX (threadid)", $link); runsql("ALTER TABLE ${mysqlprefix}chatsitevisitor ADD INDEX (threadid)", $link);
} }
$res = mysql_query("select null from information_schema.statistics where table_schema = '$mysqldb' and table_name = '${mysqlprefix}visitedpage' and index_name = 'visitorid'", $link);
if ($res && mysql_num_rows($res) == 0) {
runsql("ALTER TABLE ${mysqlprefix}visitedpage ADD INDEX (visitorid)", $link);
}
} }
} }

View File

@ -32,8 +32,8 @@ function track_visitor($visitorid, $entry, $referer, $link)
return $visitor; return $visitor;
} }
else { else {
perform_query(sprintf("update ${mysqlprefix}chatsitevisitor set lasttime = CURRENT_TIMESTAMP, path = '%s' where visitorid=" . $visitor['visitorid'], perform_query("update ${mysqlprefix}chatsitevisitor set lasttime = CURRENT_TIMESTAMP where visitorid=" . $visitor['visitorid'], $link);
db_escape_string(track_build_path($referer, $visitor['path']))), $link); track_visit_page($visitor['visitorid'], $referer, $link);
return $visitor['visitorid']; return $visitor['visitorid'];
} }
} }
@ -44,13 +44,16 @@ function track_visitor_start($entry, $referer, $link)
$visitor = visitor_from_request(); $visitor = visitor_from_request();
perform_query(sprintf("insert into ${mysqlprefix}chatsitevisitor (userid, username, firsttime, lasttime, entry, path, details) values ('%s', '%s', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '%s', '%s', '%s')", perform_query(sprintf("insert into ${mysqlprefix}chatsitevisitor (userid, username, firsttime, lasttime, entry, details) values ('%s', '%s', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '%s', '%s')",
db_escape_string($visitor['id']), db_escape_string($visitor['id']),
db_escape_string($visitor['name']), db_escape_string($visitor['name']),
db_escape_string($entry), db_escape_string($entry),
db_escape_string(track_build_path($referer, '')),
db_escape_string(track_build_details())), $link); db_escape_string(track_build_details())), $link);
if ($id) {
track_visit_page($id, $referer, $link);
}
$id = db_insert_id($link); $id = db_insert_id($link);
return $id ? $id : 0; return $id ? $id : 0;
} }
@ -75,33 +78,34 @@ function track_get_visitor_by_threadid($threadid, $link)
return $visitor; return $visitor;
} }
function track_visit_page($visitorid, $page, $link)
function track_build_path($referer, $path)
{ {
if ($path !== '') { global $mysqlprefix;
$path = unserialize($path);
krsort($path); if (empty($page)) {
return;
list($lasttime, $lastpage) = each($path); }
$lastpage = select_one_row(sprintf("select address from ${mysqlprefix}visitedpage where visitorid = '%s' order by visittime desc limit 1",
if ($referer != $lastpage) { db_escape_string($visitorid)), $link);
$path[time()] = $referer; if ( $lastpage['address'] != $page ) {
perform_query(sprintf("insert into ${mysqlprefix}visitedpage (visitorid, address, visittime) values ('%s', '%s', CURRENT_TIMESTAMP)",
db_escape_string($visitorid),
db_escape_string($page)), $link);
} }
}
else {
$path[time()] = $referer;
}
$path = serialize($path);
return $path;
} }
function track_retrieve_path($visitor) function track_get_path($visitor, $link)
{ {
return unserialize($visitor['path']); global $mysqlprefix;
$query_result = perform_query(sprintf("select address, UNIX_TIMESTAMP(visittime) as visittime from ${mysqlprefix}visitedpage where visitorid = '%s'",
db_escape_string($visitor['visitorid'])), $link);
$result = array();
while( $page = db_fetch_assoc($query_result) ){
$result[$page['visittime']] = $page['address'];
}
return $result;
} }
function track_build_details() function track_build_details()
{ {
$result = array( $result = array(

View File

@ -53,10 +53,9 @@ else {
die("Wrong visitor!"); die("Wrong visitor!");
} }
} }
$path = track_get_path($visitor, $link);
close_connection($link); close_connection($link);
$path = track_retrieve_path($visitor);
$page['entry'] = htmlspecialchars($visitor['entry']); $page['entry'] = htmlspecialchars($visitor['entry']);
$page['history'] = array(); $page['history'] = array();
ksort($path); ksort($path);