improve performance of the zotfeed queries

This commit is contained in:
friendica 2015-03-23 19:56:10 -07:00
parent d32f63df82
commit c2acab21d4
4 changed files with 23 additions and 17 deletions

View File

@ -4366,12 +4366,11 @@ function zot_feed($uid,$observer_xchan,$arr) {
$sql_extra = item_permissions_sql($uid);
}
$limit = " LIMIT 100 ";
if($mindate != NULL_DATE) {
$sql_extra .= " and ( created > '$mindate' or edited > '$mindate' ) ";
$limit = "";
}
else
$limit = " limit 0, 50 ";
if($message_id) {
$sql_extra .= " and mid = '" . dbesc($message_id) . "' ";
@ -4382,20 +4381,20 @@ function zot_feed($uid,$observer_xchan,$arr) {
if(is_sys_channel($uid)) {
require_once('include/security.php');
$r = q("SELECT distinct parent, created from item
$r = q("SELECT parent from item
WHERE uid != %d
and uid in (" . stream_perms_api_uids(PERMS_PUBLIC) . ") AND item_restrict = 0
AND (item_flags & %d)>0
and item_private = 0 $sql_extra ORDER BY created ASC $limit",
AND item_private = 0 AND item_restrict = 0 AND uid in (" . stream_perms_api_uids(PERMS_PUBLIC,10,1) . ")
AND (item_flags & %d) > 0
$sql_extra GROUP BY parent ORDER BY created ASC $limit",
intval($uid),
intval(ITEM_WALL)
);
}
else {
$r = q("SELECT distinct parent, created from item
$r = q("SELECT parent from item
WHERE uid = %d AND item_restrict = 0
AND (item_flags & %d)>0
$sql_extra ORDER BY created ASC $limit",
AND (item_flags & %d) > 0
$sql_extra GROUP BY parent ORDER BY created ASC $limit",
intval($uid),
intval(ITEM_WALL)
);

View File

@ -396,13 +396,15 @@ function init_groups_visitor($contact_id) {
// will likely be too expensive.
// Returns a string list of comma separated channel_ids suitable for direct inclusion in a SQL query
function stream_perms_api_uids($perms = NULL ) {
function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0 ) {
$perms = is_null($perms) ? (PERMS_SITE|PERMS_NETWORK|PERMS_PUBLIC) : $perms;
$ret = array();
$limit_sql = (($limit) ? " LIMIT " . intval($limit) . " " : '');
$random_sql = (($rand) ? " ORDER BY " . db_getfunc('RAND') . " " : '');
if(local_channel())
$ret[] = local_channel();
$r = q("select channel_id from channel where channel_r_stream > 0 and (channel_r_stream & %d)>0 and not (channel_pageflags & %d)>0",
$r = q("select channel_id from channel where channel_r_stream > 0 and ( channel_r_stream & %d )>0 and ( channel_pageflags & %d ) = 0 $random_sql $limit_sql ",
intval($perms),
intval(PAGE_ADULT|PAGE_CENSORED|PAGE_SYSTEM|PAGE_REMOVED)
);

View File

@ -1855,9 +1855,13 @@ function check_webbie($arr) {
function ids_to_querystr($arr,$idx = 'id') {
$t = array();
foreach($arr as $x)
if($arr) {
foreach($arr as $x) {
if(! in_array($x[$idx],$t)) {
$t[] = $x[$idx];
}
}
}
return(implode(',', $t));
}

View File

@ -9,7 +9,7 @@ function zotfeed_init(&$a) {
$mindate = (($_REQUEST['mindate']) ? datetime_convert('UTC','UTC',$_REQUEST['mindate']) : '');
if(! $mindate)
$mindate = datetime_convert('UTC','UTC', 'now - 1 month');
$mindate = datetime_convert('UTC','UTC', 'now - 4 days');
if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) {
$result['message'] = 'Public access denied';
@ -21,7 +21,7 @@ function zotfeed_init(&$a) {
$channel_address = ((argc() > 1) ? argv(1) : '');
if($channel_address) {
$r = q("select channel_id, channel_name from channel where channel_address = '%s' and not (channel_pageflags & %d)>0 limit 1",
$r = q("select channel_id, channel_name from channel where channel_address = '%s' and not (channel_pageflags & %d) > 0 limit 1",
dbesc(argv(1)),
intval(PAGE_REMOVED)
);
@ -30,6 +30,7 @@ function zotfeed_init(&$a) {
$x = get_sys_channel();
if($x)
$r = array($x);
$mindate = datetime_convert('UTC','UTC', 'now - 2 days');
}
if(! $r) {
$result['message'] = 'Channel not found.';