mirror of
https://github.com/friendica/friendica
synced 2025-01-19 08:24:27 +00:00
Merge pull request #14697 from annando/updatecontact
Only update a contact when it should be updated
This commit is contained in:
commit
f3106097af
2 changed files with 19 additions and 17 deletions
|
@ -27,6 +27,7 @@ use Friendica\Network\HTTPException;
|
|||
use Friendica\Network\HTTPException\NotModifiedException;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Security\OpenWebAuth;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Images;
|
||||
use Friendica\Util\ParseUrl;
|
||||
use Friendica\Util\Proxy;
|
||||
|
@ -297,7 +298,7 @@ class Photo extends BaseApi
|
|||
|
||||
return MPhoto::createPhotoForExternalResource($link['url'], (int)DI::userSession()->getLocalUserId(), $link['mimetype'] ?? '', $link['blurhash'] ?? '', $link['width'] ?? 0, $link['height'] ?? 0);
|
||||
case 'contact':
|
||||
$fields = ['uid', 'uri-id', 'url', 'nurl', 'avatar', 'photo', 'blurhash', 'xmpp', 'addr', 'network', 'failed', 'updated'];
|
||||
$fields = ['uid', 'uri-id', 'url', 'nurl', 'avatar', 'photo', 'blurhash', 'xmpp', 'addr', 'network', 'failed', 'updated', 'next-update'];
|
||||
$contact = Contact::getById($id, $fields);
|
||||
if (empty($contact)) {
|
||||
return false;
|
||||
|
@ -355,7 +356,7 @@ class Photo extends BaseApi
|
|||
} else {
|
||||
// Only update federated accounts that hadn't failed before and hadn't been updated recently
|
||||
$update = in_array($contact['network'], Protocol::FEDERATED) && !$contact['failed']
|
||||
&& ((time() - strtotime($contact['updated']) > 86400));
|
||||
&& ($contact['next-update'] < DateTimeFormat::utcNow());
|
||||
if ($update) {
|
||||
$curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::IMAGE, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
|
||||
$update = !$curlResult->isSuccess() && ($curlResult->getReturnCode() == 404);
|
||||
|
|
|
@ -51,6 +51,7 @@ class UpdateContact
|
|||
return 0;
|
||||
}
|
||||
|
||||
Logger::debug('Update contact', ['id' => $contact_id]);
|
||||
return Worker::add($run_parameters, 'UpdateContact', $contact_id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue