Merge pull request #4817 from annando/relais-duplicates
Avoid sending relay posts to servers that already received content
This commit is contained in:
commit
9d928417a1
2 changed files with 29 additions and 22 deletions
|
@ -49,10 +49,12 @@ class Diaspora
|
|||
*
|
||||
* The list contains not only the official relays but also servers that we serve directly
|
||||
*
|
||||
* @param integer $item_id The id of the item that is sent
|
||||
* @param integer $item_id The id of the item that is sent
|
||||
* @param array $contacts The previously fetched contacts
|
||||
*
|
||||
* @return array of relay servers
|
||||
*/
|
||||
public static function relayList($item_id)
|
||||
public static function relayList($item_id, $contacts = [])
|
||||
{
|
||||
$serverlist = [];
|
||||
|
||||
|
@ -99,15 +101,26 @@ class Diaspora
|
|||
}
|
||||
|
||||
// Now we are collecting all relay contacts
|
||||
$contacts = [];
|
||||
foreach ($serverlist as $server_url) {
|
||||
// We don't send messages to ourselves
|
||||
if (!link_compare($server_url, System::baseUrl())) {
|
||||
$cid = self::getRelayContactId($server_url);
|
||||
if (!is_bool($cid)) {
|
||||
$contacts[] = $cid;
|
||||
if (link_compare($server_url, System::baseUrl())) {
|
||||
continue;
|
||||
}
|
||||
$contact = self::getRelayContact($server_url);
|
||||
if (is_bool($contact)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$exists = false;
|
||||
foreach ($contacts as $entry) {
|
||||
if ($entry['batch'] == $contact['batch']) {
|
||||
$exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$exists) {
|
||||
$contacts[] = $contact;
|
||||
}
|
||||
}
|
||||
|
||||
return $contacts;
|
||||
|
@ -119,7 +132,7 @@ class Diaspora
|
|||
* @param string $server_url The url of the server
|
||||
* @return array with the contact
|
||||
*/
|
||||
private static function getRelayContactId($server_url)
|
||||
private static function getRelayContact($server_url)
|
||||
{
|
||||
$batch = $server_url . '/receive/public';
|
||||
|
||||
|
|
|
@ -479,15 +479,9 @@ class Notifier {
|
|||
|
||||
|
||||
if ($public_message) {
|
||||
|
||||
$r0 = [];
|
||||
$r1 = [];
|
||||
|
||||
if ($diaspora_delivery) {
|
||||
if (!$followup) {
|
||||
$r0 = Diaspora::relayList($item_id);
|
||||
}
|
||||
|
||||
$r1 = q("SELECT `batch`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`name`) AS `name`, ANY_VALUE(`network`) AS `network`
|
||||
FROM `contact` WHERE `network` = '%s' AND `batch` != ''
|
||||
AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch`",
|
||||
|
@ -500,17 +494,17 @@ class Notifier {
|
|||
// The function will ensure that there are no duplicates
|
||||
$r1 = Diaspora::participantsForThread($item_id, $r1);
|
||||
|
||||
// Add the relay to the list, avoid duplicates
|
||||
if (!$followup) {
|
||||
$r1 = Diaspora::relayList($item_id, $r1);
|
||||
}
|
||||
}
|
||||
|
||||
$r2 = q("SELECT `id`, `name`,`network` FROM `contact`
|
||||
WHERE `network` in ('%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `rel` != %d",
|
||||
dbesc(NETWORK_DFRN),
|
||||
intval($owner['uid']),
|
||||
intval(CONTACT_IS_SHARING)
|
||||
);
|
||||
$condition = ['network' => NETWORK_DFRN, 'uid' => $owner['uid'], 'blocked' => false,
|
||||
'pending' => false, 'archive' => false, 'rel' => [CONTACT_IS_FOLLOWER, CONTACT_IS_FRIEND]];
|
||||
$r2 = dba::inArray(dba::select('contact', ['id', 'name', 'network'], $condition));
|
||||
|
||||
|
||||
$r = array_merge($r2, $r1, $r0);
|
||||
$r = array_merge($r2, $r1);
|
||||
|
||||
if (DBM::is_result($r)) {
|
||||
logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG);
|
||||
|
|
Loading…
Reference in a new issue