mod_search: fix the group by mess

This commit is contained in:
zotlabs 2018-01-21 17:06:38 -08:00
parent 764d6e3407
commit a4588af0f8
2 changed files with 14 additions and 13 deletions

View File

@ -142,9 +142,9 @@ class Config {
/**
* @brief Returns a value directly from the database configuration storage.
* @brief Returns a record directly from the database configuration storage.
*
* This function queries directly the database and bypasses the chached storage
* This function queries directly the database and bypasses the cached storage
* from get_config($family, $key).
*
* @param string $family

View File

@ -165,40 +165,41 @@ class Search extends \Zotlabs\Web\Controller {
if($load) {
$r = null;
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
$prefix = 'distinct on (created, mid)';
$suffix = 'ORDER BY created DESC, mid';
} else {
$prefix = 'distinct';
$suffix = 'group by mid ORDER BY created DESC';
}
if(local_channel()) {
$r = q("SELECT $prefix mid, item.id as item_id, item.* from item
$r = q("SELECT mid, MAX(id) as item_id from item
WHERE ((( item.allow_cid = '' AND item.allow_gid = '' AND item.deny_cid = '' AND item.deny_gid = '' AND item_private = 0 )
OR ( item.uid = %d )) OR item.owner_xchan = '%s' )
$item_normal
$sql_extra
$suffix $pager_sql ",
group by mid order by created desc $pager_sql ",
intval(local_channel()),
dbesc($sys['xchan_hash'])
);
}
if($r === null) {
$r = q("SELECT $prefix mid, item.id as item_id, item.* from item
$r = q("SELECT mid, MAX(id) as item_id from item
WHERE (((( item.allow_cid = '' AND item.allow_gid = '' AND item.deny_cid = ''
AND item.deny_gid = '' AND item_private = 0 )
and owner_xchan in ( " . stream_perms_xchans(($observer) ? (PERMS_NETWORK|PERMS_PUBLIC) : PERMS_PUBLIC) . " ))
$pub_sql ) OR owner_xchan = '%s')
$item_normal
$sql_extra
$suffix $pager_sql",
group by mid order by created desc $pager_sql",
dbesc($sys['xchan_hash'])
);
}
if($r) {
$str = ids_to_querystr($r,'item_id');
$r = q("select *, id as item_id from item where id in ( " . $str . ") ");
}
}
else {
$r = array();
}
}
if($r) {