Some more improved queries

This commit is contained in:
Michael Vogel 2016-10-21 18:25:21 +00:00
commit 501c45def5
9 changed files with 50 additions and 17 deletions

View file

@ -27,9 +27,9 @@ function display_init(&$a) {
// Or is it anywhere on the server?
if ($nick == "") {
$r = qu("SELECT STRAIGHT_JOIN `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`,
$r = qu("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`,
`item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body`
FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
@ -236,7 +236,7 @@ function display_content(&$a, $update = 0) {
}
if ($nick == "") {
$r = qu("SELECT STRAIGHT_JOIN `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
$r = qu("SELECT `user`.`nickname`, `item`.`id` FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''

View file

@ -788,6 +788,9 @@ function item_post(&$a) {
} else
$post_id = 0;
q("COMMIT;");
q("START TRANSACTION;");
$r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,
`owner-name`,`owner-link`,`owner-avatar`, `owner-id`,
`author-name`, `author-link`, `author-avatar`, `author-id`,
@ -864,6 +867,7 @@ function item_post(&$a) {
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($datarray['uri']));
if(!count($r)) {
q("COMMIT");
logger('mod_item: unable to retrieve post that was just stored.');
notice( t('System error. Post not saved.') . EOL);
goaway($a->get_baseurl() . "/" . $return_path );
@ -986,6 +990,8 @@ function item_post(&$a) {
create_tags_from_item($post_id);
create_files_from_item($post_id);
q("COMMIT");
if ($post_id == $parent)
add_thread($post_id);
else {

View file

@ -53,8 +53,8 @@ function photos_init(&$a) {
$sql_extra = permissions_sql($a->data['user']['uid']);
$albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
$sql_extra group by album order by created desc",
$albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` USE INDEX (`uid_album_created`) WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
$sql_extra GROUP BY `album` ORDER BY `created` DESC",
intval($a->data['user']['uid']),
dbesc('Contact Photos'),
dbesc( t('Contact Photos'))