Skip to content

Commit

Permalink
fixed performance
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahY committed Oct 18, 2012
1 parent 07b212e commit 47ccea6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
64 changes: 33 additions & 31 deletions qa-history-layer.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -142,17 +142,13 @@ function user_activity_form() {
} }
else $last_visit = time(); else $last_visit = time();


$events = qa_db_query_sub( $event_query = qa_db_query_sub(
"SELECT "SELECT
e.event, e.event,
BINARY e.params as params, BINARY e.params as params,
UNIX_TIMESTAMP(e.datetime) AS datetime, UNIX_TIMESTAMP(e.datetime) AS datetime
p.postid AS postid
FROM FROM
^eventlog AS e ^eventlog AS e
LEFT JOIN
^posts AS p
ON e.params LIKE CONCAT('%postid=', p.postid, '\t%' ) OR e.params LIKE CONCAT('%postid=', p.postid)
WHERE WHERE
e.userid=# e.userid=#
AND AND
Expand All @@ -161,6 +157,8 @@ function user_activity_form() {
.(qa_opt('user_act_list_max')?" LIMIT ".(int)qa_opt('user_act_list_max'):""), .(qa_opt('user_act_list_max')?" LIMIT ".(int)qa_opt('user_act_list_max'):""),
$userid, qa_opt('user_act_list_age') $userid, qa_opt('user_act_list_age')
); );

error_log(count($event_query));


// no post // no post


Expand Down Expand Up @@ -221,10 +219,32 @@ function user_activity_form() {


$fields = array(); $fields = array();


while ( ($event=qa_db_read_one_assoc($events,true)) !== null ) { $events = array();
$postids = array();
while ( ($event=qa_db_read_one_assoc($event_query,true)) !== null ) {
if(preg_match('/postid=([0-9]+)/',$event['params'],$m) == 1) {
$event['postid'] = (int)$m[1];
$postids[] = (int)$m[1];
}
$events[$m[1]] = $event;
}

// get post info, also makes sure post exists

$posts = null;
if(!empty($postids)) {
$posts = qa_db_read_all_assoc(
qa_db_query_sub(
'SELECT postid,type,parentid,BINARY title as title FROM ^posts WHERE postid IN ('.implode(',',$postids).')'
)
);
foreach($posts as $post) {
$events[(string)$post['postid']]['post'] = $post;
}
}

foreach($events as $event) {
$type = $event['event']; $type = $event['event'];




// these calls allow you to deal with deleted events; // these calls allow you to deal with deleted events;
// uncomment the first one to skip them // uncomment the first one to skip them
Expand Down Expand Up @@ -283,14 +303,8 @@ function user_activity_form() {
else if($type == 'badge_awarded') { else if($type == 'badge_awarded') {
if(!qa_opt('badge_active') || !function_exists('qa_get_badge_type')) if(!qa_opt('badge_active') || !function_exists('qa_get_badge_type'))
continue; continue;
if(isset($params['postid'])) { if(isset($event['post'])) {
$post = qa_db_read_one_assoc( $post = $event['post'];
qa_db_query_sub(
'SELECT type,parentid,BINARY title as title FROM ^posts WHERE postid=#',
$params['postid']
),
true
);


if(strpos($post['type'],'Q') !== 0) { if(strpos($post['type'],'Q') !== 0) {
$anchor = qa_anchor((strpos($post['type'],'A') === 0 ?'A':'C'), $params['postid']); $anchor = qa_anchor((strpos($post['type'],'A') === 0 ?'A':'C'), $params['postid']);
Expand Down Expand Up @@ -321,13 +335,7 @@ function user_activity_form() {
} }
else if(strpos($event['event'],'q_') !== 0 && strpos($event['event'],'in_q_') !== 0) { // comment or answer else if(strpos($event['event'],'q_') !== 0 && strpos($event['event'],'in_q_') !== 0) { // comment or answer
if(!isset($params['parentid'])) { if(!isset($params['parentid'])) {
$params['parentid'] = qa_db_read_one_value( $params['parentid'] = $event['post']['parentid'];
qa_db_query_sub(
'SELECT parentid FROM ^posts WHERE postid=#',
$params['postid']
),
true
);
} }


$parent = qa_db_select_with_pending( $parent = qa_db_select_with_pending(
Expand All @@ -352,13 +360,7 @@ function user_activity_form() {
else { // question else { // question


if(!isset($params['title'])) { if(!isset($params['title'])) {
$params['title'] = qa_db_read_one_value( $params['title'] = $event['post']['title'];
qa_db_query_sub(
'SELECT BINARY title as title FROM ^posts WHERE postid=#',
$params['postid']
),
true
);
} }
if($params['title'] !== null) { if($params['title'] !== null) {
$activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url')); $activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url'));
Expand Down
2 changes: 1 addition & 1 deletion qa-plugin.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: History Plugin Name: History
Plugin URI: https://github.com/NoahY/q2a-history Plugin URI: https://github.com/NoahY/q2a-history
Plugin Description: Adds complete activity history list to user profile Plugin Description: Adds complete activity history list to user profile
Plugin Version: 1.5 Plugin Version: 1.6
Plugin Date: 2011-10-26 Plugin Date: 2011-10-26
Plugin Author: NoahY Plugin Author: NoahY
Plugin Author URI: http://www.question2answer.org/qa/user/NoahY Plugin Author URI: http://www.question2answer.org/qa/user/NoahY
Expand Down

0 comments on commit 47ccea6

Please sign in to comment.