mirror of
https://github.com/friendica/friendica
synced 2025-03-04 14:28:26 +00:00
Merge pull request #14686 from annando/relation
Improves the performance for contact relation discovery
This commit is contained in:
commit
8bf3d6694a
2 changed files with 29 additions and 7 deletions
|
@ -10,6 +10,7 @@ namespace Friendica\Model\Contact;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Content\Widget;
|
use Friendica\Content\Widget;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
@ -22,6 +23,7 @@ use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
use Friendica\Worker\AddContact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides relationship information based on the `contact-relation` table.
|
* This class provides relationship information based on the `contact-relation` table.
|
||||||
|
@ -162,20 +164,22 @@ class Relation
|
||||||
$following_counter = 0;
|
$following_counter = 0;
|
||||||
|
|
||||||
DI::logger()->info('Discover contacts', ['id' => $target, 'url' => $url, 'contacts' => count($contacts)]);
|
DI::logger()->info('Discover contacts', ['id' => $target, 'url' => $url, 'contacts' => count($contacts)]);
|
||||||
foreach ($contacts as $contact) {
|
foreach ($contacts as $contact_url) {
|
||||||
$actor = Contact::getIdForURL($contact);
|
$contact = Contact::getByURL($contact_url, false, ['id']);
|
||||||
if (!empty($actor)) {
|
if (!empty($contact['id'])) {
|
||||||
if (in_array($contact, $followers)) {
|
if (in_array($contact_url, $followers)) {
|
||||||
$fields = ['cid' => $target, 'relation-cid' => $actor, 'follows' => true, 'follow-updated' => DateTimeFormat::utcNow()];
|
$fields = ['cid' => $target, 'relation-cid' => $contact['id'], 'follows' => true, 'follow-updated' => DateTimeFormat::utcNow()];
|
||||||
DBA::insert('contact-relation', $fields, Database::INSERT_UPDATE);
|
DBA::insert('contact-relation', $fields, Database::INSERT_UPDATE);
|
||||||
$follower_counter++;
|
$follower_counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($contact, $followings)) {
|
if (in_array($contact_url, $followings)) {
|
||||||
$fields = ['cid' => $actor, 'relation-cid' => $target, 'follows' => true, 'follow-updated' => DateTimeFormat::utcNow()];
|
$fields = ['cid' => $contact['id'], 'relation-cid' => $target, 'follows' => true, 'follow-updated' => DateTimeFormat::utcNow()];
|
||||||
DBA::insert('contact-relation', $fields, Database::INSERT_UPDATE);
|
DBA::insert('contact-relation', $fields, Database::INSERT_UPDATE);
|
||||||
$following_counter++;
|
$following_counter++;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
AddContact::add(Worker::PRIORITY_LOW, 0, $contact_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,12 @@
|
||||||
|
|
||||||
namespace Friendica\Worker;
|
namespace Friendica\Worker;
|
||||||
|
|
||||||
|
use Friendica\Core\Worker;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
class AddContact
|
class AddContact
|
||||||
{
|
{
|
||||||
|
@ -39,4 +41,20 @@ class AddContact
|
||||||
DI::logger()->notice('Imagick not found.', ['exception' => $e, 'uid' => $uid, 'url' => $url]);
|
DI::logger()->notice('Imagick not found.', ['exception' => $e, 'uid' => $uid, 'url' => $url]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|int $run_parameters Priority constant or array of options described in Worker::add
|
||||||
|
* @param int $uid User ID
|
||||||
|
* @param string $url Contact link
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function add($run_parameters, int $uid, string $url): int
|
||||||
|
{
|
||||||
|
if (Network::isUrlBlocked($url)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DI::logger()->debug('Add contact', ['uid' => $uid, 'url' => $url]);
|
||||||
|
return Worker::add($run_parameters, 'AddContact', 0, $url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue