start fixing all the item queries

This commit is contained in:
friendica
2012-10-07 18:44:06 -07:00
parent c612253627
commit a56c0425e6
5 changed files with 45 additions and 50 deletions

View File

@@ -227,7 +227,7 @@ function item_post(&$a) {
$app = $orig_post['app'];
$title = escape_tags(trim($_REQUEST['title']));
$body = escape_tags(trim($_REQUEST['body']));
$private = $orig_post['private'];
$private = $orig_post['item_private'];
}
else {
@@ -273,12 +273,12 @@ function item_post(&$a) {
if($parent_item) {
$private = 0;
if(($parent_item['private'])
if(($parent_item['item_private'])
|| strlen($parent_item['allow_cid'])
|| strlen($parent_item['allow_gid'])
|| strlen($parent_item['deny_cid'])
|| strlen($parent_item['deny_gid'])) {
$private = (($parent_item['private']) ? $parent_item['private'] : 1);
$private = (($parent_item['item_private']) ? $parent_item['item_private'] : 1);
}
$str_contact_allow = $parent_item['allow_cid'];
@@ -597,7 +597,7 @@ function item_post(&$a) {
$datarray['allow_gid'] = $str_group_allow;
$datarray['deny_cid'] = $str_contact_deny;
$datarray['deny_gid'] = $str_group_deny;
$datarray['private'] = $private;
$datarray['item_private'] = $private;
$datarray['attach'] = $attachments;
$datarray['thr_parent'] = $thr_parent;
$datarray['postopts'] = '';
@@ -707,7 +707,7 @@ function item_post(&$a) {
// Inherit ACL's from the parent item.
$r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
$r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `item_private` = %d
WHERE `id` = %d LIMIT 1",
dbesc($parent_item['allow_cid']),
dbesc($parent_item['allow_gid']),

View File

@@ -414,8 +414,8 @@ function network_content(&$a, $update = 0, $load = false) {
$sql_options = (($star) ? " and starred = 1 " : '');
$sql_nets = '';
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
// fixme
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE id = parent $sql_options ) ";
if($group) {
$r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -604,15 +604,12 @@ function network_content(&$a, $update = 0, $load = false) {
// "New Item View" - show all items unthreaded in reverse created date order
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn_id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, `contact`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1
AND `item`.`deleted` = 0 and `item`.`moderated` = 0
o.xchan_name as oname, o.xchan_photo as ophoto, o.xchan_profile as ourl,
a.xchan_name as aname, a.xchan_photo as aphoto, a.xchan_profile as aurl,
FROM `item` left join xchan as o on xchan_hash = owner_xchan left join xchan as a
on xchan_hash = author_xchan
WHERE `item`.`uid` = %d AND item_restrict = 0
$simple_update
AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra $sql_nets
ORDER BY `item`.`received` DESC $pager_sql ",
intval($_SESSION['uid'])
@@ -647,10 +644,8 @@ function network_content(&$a, $update = 0, $load = false) {
}
else {
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
FROM `item` 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
$r = q("SELECT `item`.`id` AS `item_id`
FROM `item` WHERE `item`.`uid` = %d AND `item`.`item_restrict` = 0
AND `item`.`parent` = `item`.`id`
$sql_extra3 $sql_extra $sql_nets
ORDER BY `item`.$ordering DESC $pager_sql ",
@@ -661,18 +656,16 @@ function network_content(&$a, $update = 0, $load = false) {
// Then fetch all the children of the parents that are on this page
if(count($r)) {
if($r && count($r)) {
$parents_str = ids_to_querystr($r,'item_id');
$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 `item`, `contact`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
o.xchan_name as oname, o.xchan_photo as ophoto, o.xchan_profile as ourl,
a.xchan_name as aname, a.xchan_photo as aphoto, a.xchan_profile as aurl,
FROM `item` left join xchan as o on xchan_hash = owner_xchan left join xchan as a
on xchan_hash = author_xchan
WHERE `item`.`uid` = %d AND `item`.`item_restrict` = 0
AND `item`.`parent` IN ( %s )
$sql_extra ",
intval(local_user()),
@@ -696,8 +689,10 @@ function network_content(&$a, $update = 0, $load = false) {
// at the top level network page just mark everything seen.
if((! $group) && (! $cid) && (! $star)) {
$r = q("UPDATE `item` SET `unseen` = 0
WHERE `unseen` = 1 AND `uid` = %d",
$r = q("UPDATE `item` SET item_flags = item_flags & (! %d)
WHERE item_flags & %d AND `uid` = %d",
intval(ITEM_UNSEEN),
intval(ITEM_UNSEEN),
intval(local_user())
);
}

View File

@@ -99,13 +99,10 @@ function ping_init(&$a) {
$t1 = dba_timer();
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
`item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,
`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
`item`.`deleted` = 0 AND `item`.`uid` = %d
ORDER BY `item`.`created` DESC",
$r = q("SELECT id, item_restrict, item_flags FROM item
WHERE item_restrict = %d and item_flags & %d and `item`.`uid` = %d",
intval(ITEM_VISIBLE),
intval(ITEM_UNSEEN),
intval(local_user())
);
@@ -115,7 +112,7 @@ function ping_init(&$a) {
call_hooks('network_ping', $arr);
foreach ($r as $it) {
if($it['wall'])
if($it['item_flags'] & ITEM_WALL)
$result['home'] ++;
else
$result['network'] ++;

View File

@@ -221,7 +221,7 @@ function profile_content(&$a, $update = 0) {
}
if(count($r)) {
if($r && count($r)) {
$parents_str = ids_to_querystr($r,'item_id');