aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2015-03-23 19:56:10 -0700
committerfriendica <info@friendica.com>2015-03-23 19:56:10 -0700
commitc2acab21d44bfaa8e051a42a13b72c056c95b0a3 (patch)
tree9bed606355434db496ecca9aaca04fcac4993381
parentd32f63df82de01f66d5babe932f20aed9a5b3ee2 (diff)
downloadvolse-hubzilla-c2acab21d44bfaa8e051a42a13b72c056c95b0a3.tar.gz
volse-hubzilla-c2acab21d44bfaa8e051a42a13b72c056c95b0a3.tar.bz2
volse-hubzilla-c2acab21d44bfaa8e051a42a13b72c056c95b0a3.zip
improve performance of the zotfeed queries
-rwxr-xr-xinclude/items.php19
-rw-r--r--include/security.php6
-rw-r--r--include/text.php10
-rw-r--r--mod/zotfeed.php5
4 files changed, 23 insertions, 17 deletions
diff --git a/include/items.php b/include/items.php
index 8e293d761..32e5dcbe5 100755
--- a/include/items.php
+++ b/include/items.php
@@ -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)
);
diff --git a/include/security.php b/include/security.php
index e9b41dcf9..c3b0e9763 100644
--- a/include/security.php
+++ b/include/security.php
@@ -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)
);
diff --git a/include/text.php b/include/text.php
index 86da3ee42..a21d8029f 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1855,9 +1855,13 @@ function check_webbie($arr) {
function ids_to_querystr($arr,$idx = 'id') {
$t = array();
- foreach($arr as $x)
- $t[] = $x[$idx];
-
+ if($arr) {
+ foreach($arr as $x) {
+ if(! in_array($x[$idx],$t)) {
+ $t[] = $x[$idx];
+ }
+ }
+ }
return(implode(',', $t));
}
diff --git a/mod/zotfeed.php b/mod/zotfeed.php
index 7bf91d4db..78a667330 100644
--- a/mod/zotfeed.php
+++ b/mod/zotfeed.php
@@ -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.';