Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed performance

  • Loading branch information...
commit 47ccea6d616f2d5f3a7b54a85f000e7ac566a7c7 1 parent 07b212e
@NoahY authored
Showing with 34 additions and 32 deletions.
  1. +33 −31 qa-history-layer.php
  2. +1 −1  qa-plugin.php
View
64 qa-history-layer.php
@@ -142,17 +142,13 @@ function user_activity_form() {
}
else $last_visit = time();
- $events = qa_db_query_sub(
+ $event_query = qa_db_query_sub(
"SELECT
e.event,
BINARY e.params as params,
- UNIX_TIMESTAMP(e.datetime) AS datetime,
- p.postid AS postid
+ UNIX_TIMESTAMP(e.datetime) AS datetime
FROM
^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
e.userid=#
AND
@@ -161,6 +157,8 @@ function user_activity_form() {
.(qa_opt('user_act_list_max')?" LIMIT ".(int)qa_opt('user_act_list_max'):""),
$userid, qa_opt('user_act_list_age')
);
+
+ error_log(count($event_query));
// no post
@@ -221,10 +219,32 @@ function user_activity_form() {
$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'];
-
-
// these calls allow you to deal with deleted events;
// uncomment the first one to skip them
@@ -283,14 +303,8 @@ function user_activity_form() {
else if($type == 'badge_awarded') {
if(!qa_opt('badge_active') || !function_exists('qa_get_badge_type'))
continue;
- if(isset($params['postid'])) {
- $post = qa_db_read_one_assoc(
- qa_db_query_sub(
- 'SELECT type,parentid,BINARY title as title FROM ^posts WHERE postid=#',
- $params['postid']
- ),
- true
- );
+ if(isset($event['post'])) {
+ $post = $event['post'];
if(strpos($post['type'],'Q') !== 0) {
$anchor = qa_anchor((strpos($post['type'],'A') === 0 ?'A':'C'), $params['postid']);
@@ -321,13 +335,7 @@ function user_activity_form() {
}
else if(strpos($event['event'],'q_') !== 0 && strpos($event['event'],'in_q_') !== 0) { // comment or answer
if(!isset($params['parentid'])) {
- $params['parentid'] = qa_db_read_one_value(
- qa_db_query_sub(
- 'SELECT parentid FROM ^posts WHERE postid=#',
- $params['postid']
- ),
- true
- );
+ $params['parentid'] = $event['post']['parentid'];
}
$parent = qa_db_select_with_pending(
@@ -352,13 +360,7 @@ function user_activity_form() {
else { // question
if(!isset($params['title'])) {
- $params['title'] = qa_db_read_one_value(
- qa_db_query_sub(
- 'SELECT BINARY title as title FROM ^posts WHERE postid=#',
- $params['postid']
- ),
- true
- );
+ $params['title'] = $event['post']['title'];
}
if($params['title'] !== null) {
$activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url'));
View
2  qa-plugin.php
@@ -3,7 +3,7 @@
Plugin Name: History
Plugin URI: https://github.com/NoahY/q2a-history
Plugin Description: Adds complete activity history list to user profile
- Plugin Version: 1.5
+ Plugin Version: 1.6
Plugin Date: 2011-10-26
Plugin Author: NoahY
Plugin Author URI: http://www.question2answer.org/qa/user/NoahY
Please sign in to comment.
Something went wrong with that request. Please try again.