Merge pull request #849 from annando/master
SQL improvements. New parameter for a maximum amount of comments per thread
This commit is contained in:
commit
19984f786b
3 changed files with 75 additions and 33 deletions
|
@ -2108,11 +2108,20 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
|
||||||
$datarray['type'] = 'activity';
|
$datarray['type'] = 'activity';
|
||||||
$datarray['gravity'] = GRAVITY_LIKE;
|
$datarray['gravity'] = GRAVITY_LIKE;
|
||||||
// only one like or dislike per person
|
// only one like or dislike per person
|
||||||
$r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
|
// splitted into two queries for performance issues
|
||||||
|
$r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s') limit 1",
|
||||||
|
intval($datarray['uid']),
|
||||||
|
intval($datarray['contact-id']),
|
||||||
|
dbesc($datarray['verb']),
|
||||||
|
dbesc($parent_uri)
|
||||||
|
);
|
||||||
|
if($r && count($r))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`thr-parent` = '%s') limit 1",
|
||||||
intval($datarray['uid']),
|
intval($datarray['uid']),
|
||||||
intval($datarray['contact-id']),
|
intval($datarray['contact-id']),
|
||||||
dbesc($datarray['verb']),
|
dbesc($datarray['verb']),
|
||||||
dbesc($parent_uri),
|
|
||||||
dbesc($parent_uri)
|
dbesc($parent_uri)
|
||||||
);
|
);
|
||||||
if($r && count($r))
|
if($r && count($r))
|
||||||
|
@ -3009,11 +3018,21 @@ function local_delivery($importer,$data) {
|
||||||
$datarray['gravity'] = GRAVITY_LIKE;
|
$datarray['gravity'] = GRAVITY_LIKE;
|
||||||
$datarray['last-child'] = 0;
|
$datarray['last-child'] = 0;
|
||||||
// only one like or dislike per person
|
// only one like or dislike per person
|
||||||
$r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s' or `parent-uri` = '%s') and deleted = 0 limit 1",
|
// splitted into two queries for performance issues
|
||||||
|
$r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`parent-uri` = '%s') and deleted = 0 limit 1",
|
||||||
|
intval($datarray['uid']),
|
||||||
|
intval($datarray['contact-id']),
|
||||||
|
dbesc($datarray['verb']),
|
||||||
|
dbesc($datarray['parent-uri'])
|
||||||
|
|
||||||
|
);
|
||||||
|
if($r && count($r))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s') and deleted = 0 limit 1",
|
||||||
intval($datarray['uid']),
|
intval($datarray['uid']),
|
||||||
intval($datarray['contact-id']),
|
intval($datarray['contact-id']),
|
||||||
dbesc($datarray['verb']),
|
dbesc($datarray['verb']),
|
||||||
dbesc($datarray['parent-uri']),
|
|
||||||
dbesc($datarray['parent-uri'])
|
dbesc($datarray['parent-uri'])
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -3181,11 +3200,20 @@ function local_delivery($importer,$data) {
|
||||||
$datarray['type'] = 'activity';
|
$datarray['type'] = 'activity';
|
||||||
$datarray['gravity'] = GRAVITY_LIKE;
|
$datarray['gravity'] = GRAVITY_LIKE;
|
||||||
// only one like or dislike per person
|
// only one like or dislike per person
|
||||||
$r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
|
// splitted into two queries for performance issues
|
||||||
|
$r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s') limit 1",
|
||||||
|
intval($datarray['uid']),
|
||||||
|
intval($datarray['contact-id']),
|
||||||
|
dbesc($datarray['verb']),
|
||||||
|
dbesc($parent_uri)
|
||||||
|
);
|
||||||
|
if($r && count($r))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`thr-parent` = '%s') limit 1",
|
||||||
intval($datarray['uid']),
|
intval($datarray['uid']),
|
||||||
intval($datarray['contact-id']),
|
intval($datarray['contact-id']),
|
||||||
dbesc($datarray['verb']),
|
dbesc($datarray['verb']),
|
||||||
dbesc($parent_uri),
|
|
||||||
dbesc($parent_uri)
|
dbesc($parent_uri)
|
||||||
);
|
);
|
||||||
if($r && count($r))
|
if($r && count($r))
|
||||||
|
|
|
@ -806,22 +806,36 @@ function network_content(&$a, $update = 0) {
|
||||||
foreach($r as $rr)
|
foreach($r as $rr)
|
||||||
if(! in_array($rr['item_id'],$parents_arr))
|
if(! in_array($rr['item_id'],$parents_arr))
|
||||||
$parents_arr[] = $rr['item_id'];
|
$parents_arr[] = $rr['item_id'];
|
||||||
$parents_str = implode(', ', $parents_arr);
|
|
||||||
|
|
||||||
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
|
//$parents_str = implode(', ', $parents_arr);
|
||||||
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
|
|
||||||
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
|
||||||
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
|
|
||||||
FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
|
||||||
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
|
|
||||||
AND `item`.`moderated` = 0
|
|
||||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
|
||||||
AND `item`.`parent` IN ( %s )
|
|
||||||
$sql_extra ",
|
|
||||||
intval(local_user()),
|
|
||||||
dbesc($parents_str)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// splitted into separate queries to avoid the problem with very long threads
|
||||||
|
// so always the last X comments are loaded
|
||||||
|
// This problem can occur expecially with imported facebook posts
|
||||||
|
$max_comments = get_config("system", "max_comments");
|
||||||
|
if ($max_comments == 0)
|
||||||
|
$max_comments = 1000;
|
||||||
|
|
||||||
|
$items = array();
|
||||||
|
|
||||||
|
foreach ($parents_arr AS $parents_str) {
|
||||||
|
|
||||||
|
$thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
|
||||||
|
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
|
||||||
|
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
||||||
|
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
|
||||||
|
FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||||
|
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
|
||||||
|
AND `item`.`moderated` = 0
|
||||||
|
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||||
|
AND `item`.`parent` IN ( %s )
|
||||||
|
$sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
|
||||||
|
intval(local_user()),
|
||||||
|
dbesc($parents_str),
|
||||||
|
intval($max_comments + 1)
|
||||||
|
);
|
||||||
|
$items = array_merge($items, $thread_items);
|
||||||
|
}
|
||||||
$items = conv_sort($items,$ordering);
|
$items = conv_sort($items,$ordering);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,19 +17,19 @@ function user_allow($hash) {
|
||||||
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||||
intval($register[0]['uid'])
|
intval($register[0]['uid'])
|
||||||
);
|
);
|
||||||
|
|
||||||
if(! count($user))
|
if(! count($user))
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
$r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
|
$r = q("DELETE FROM `register` WHERE `hash` = '%s'",
|
||||||
dbesc($register[0]['hash'])
|
dbesc($register[0]['hash'])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d LIMIT 1",
|
$r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
|
||||||
intval($register[0]['uid'])
|
intval($register[0]['uid'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
|
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
|
||||||
intval($user[0]['uid'])
|
intval($user[0]['uid'])
|
||||||
);
|
);
|
||||||
|
@ -62,7 +62,7 @@ function user_allow($hash) {
|
||||||
if($res) {
|
if($res) {
|
||||||
info( t('Account approved.') . EOL );
|
info( t('Account approved.') . EOL );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,23 +83,23 @@ function user_deny($hash) {
|
||||||
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||||
intval($register[0]['uid'])
|
intval($register[0]['uid'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
|
$r = q("DELETE FROM `user` WHERE `uid` = %d",
|
||||||
intval($register[0]['uid'])
|
intval($register[0]['uid'])
|
||||||
);
|
);
|
||||||
$r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
|
$r = q("DELETE FROM `contact` WHERE `uid` = %d",
|
||||||
intval($register[0]['uid'])
|
intval($register[0]['uid'])
|
||||||
);
|
);
|
||||||
$r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
|
$r = q("DELETE FROM `profile` WHERE `uid` = %d",
|
||||||
intval($register[0]['uid'])
|
intval($register[0]['uid'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
|
$r = q("DELETE FROM `register` WHERE `hash` = '%s'",
|
||||||
dbesc($register[0]['hash'])
|
dbesc($register[0]['hash'])
|
||||||
);
|
);
|
||||||
notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
|
notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function regmod_content(&$a) {
|
function regmod_content(&$a) {
|
||||||
|
|
Loading…
Reference in a new issue