From 53c1bf6ba321970fe7de551044f7951f002b57ec Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Sat, 22 Apr 2017 22:08:05 +0200 Subject: [PATCH 1/3] improve profile update for non logged in ussers and remote users --- index.php | 4 ++++ mod/profile.php | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index ebc65cdb0..efaf07c1a 100644 --- a/index.php +++ b/index.php @@ -174,6 +174,10 @@ if (! x($_SESSION,'sysmsg_info')) { $_SESSION['sysmsg_info'] = array(); } +// Array for informations about last received items +if (! x($_SESSION,'last_updated')) { + $_SESSION['last_updated'] = array(); +} /* * check_config() is responsible for running update scripts. These automatically * update the DB schema whenever we push a new one out. It also checks to see if diff --git a/mod/profile.php b/mod/profile.php index a83cb076f..259e08608 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -149,6 +149,7 @@ function profile_content(App $a, $update = 0) { } $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false); + $last_updated_key = "profile:" . $a->profile['profile_uid'] . ":" . local_user() . ":" . remote_user(); if ($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) { notice( t('Access to this profile has been restricted.') . EOL); @@ -195,9 +196,9 @@ function profile_content(App $a, $update = 0) { 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'), 'profile_uid' => $a->profile['profile_uid'], 'acl_data' => ( $is_owner ? construct_acl_data($a, $a->user) : '' ), // For non-Javascript ACL selector - ); + ); - $o .= status_editor($a,$x); + $o .= status_editor($a,$x); } } @@ -209,6 +210,14 @@ function profile_content(App $a, $update = 0) { if ($update) { + // If the page user is the owner of the page we should query for unseen + // items. Otherwise use a timestamp of the last succesful update request. + if ($is_owner) { + $sql_extra4 = " AND `item`.`unseen`"; + } else { + $last_updated = gmdate("Y-m-d H:i:s", $_SESSION['last_updated'][$last_updated_key]); + $sql_extra4 = " AND `item`.`received` > '" . $last_updated . "'"; + } $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`, `item`.`created` FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` @@ -217,13 +226,18 @@ function profile_content(App $a, $update = 0) { (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "' OR item.verb = '" . ACTIVITY_ATTEND . "' OR item.verb = '" . ACTIVITY_ATTENDNO . "' OR item.verb = '" . ACTIVITY_ATTENDMAYBE . "') - AND `item`.`moderated` = 0 and `item`.`unseen` = 1 + AND `item`.`moderated` = 0 AND `item`.`wall` = 1 + $sql_extra4 $sql_extra ORDER BY `item`.`created` DESC", intval($a->profile['profile_uid']) ); + if (!dbm::is_result($r)) { + return ''; + } + } else { $sql_post_table = ""; @@ -283,11 +297,16 @@ function profile_content(App $a, $update = 0) { ORDER BY `thread`.`created` DESC $pager_sql", intval($a->profile['profile_uid']) ); + } $parents_arr = array(); $parents_str = ''; + // Set a time stamp for this page. We will make use of it when we + // search fornew items (update routine) + $_SESSION['last_updated'][$last_updated_key] = time(); + if (dbm::is_result($r)) { foreach($r as $rr) $parents_arr[] = $rr['item_id']; From 5a7b9676ff5efcccfbcf130ab87defb3a803e3e0 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Sat, 22 Apr 2017 22:10:43 +0200 Subject: [PATCH 2/3] fixed typo --- mod/profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/profile.php b/mod/profile.php index 259e08608..3e98906b3 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -304,7 +304,7 @@ function profile_content(App $a, $update = 0) { $parents_str = ''; // Set a time stamp for this page. We will make use of it when we - // search fornew items (update routine) + // search for new items (update routine) $_SESSION['last_updated'][$last_updated_key] = time(); if (dbm::is_result($r)) { From 88602de604ca7de0c3d51b24012cf7ee12a87c84 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Sun, 23 Apr 2017 16:22:53 +0200 Subject: [PATCH 3/3] fall back to unseen items if no timestamp is available --- mod/profile.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mod/profile.php b/mod/profile.php index 3e98906b3..838a55094 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -210,13 +210,15 @@ function profile_content(App $a, $update = 0) { if ($update) { + $last_updated = (x($_SESSION['last_updated'], $last_updated_key) ? $_SESSION['last_updated'][$last_updated_key] : 0); + // If the page user is the owner of the page we should query for unseen // items. Otherwise use a timestamp of the last succesful update request. - if ($is_owner) { + if ($is_owner || !$last_updated) { $sql_extra4 = " AND `item`.`unseen`"; } else { - $last_updated = gmdate("Y-m-d H:i:s", $_SESSION['last_updated'][$last_updated_key]); - $sql_extra4 = " AND `item`.`received` > '" . $last_updated . "'"; + $gmupdate = gmdate("Y-m-d H:i:s", $last_updated); + $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'"; } $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`, `item`.`created`