From dc382b5288cc62bda17ac238e320fe00323993d1 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Jan 2025 06:06:28 +0000 Subject: [PATCH 1/2] Changed contact update rule / added logging --- src/Module/Photo.php | 5 +++-- src/Worker/UpdateContact.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 30e6d57672..87da6be55b 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -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); diff --git a/src/Worker/UpdateContact.php b/src/Worker/UpdateContact.php index aad6a93db2..ded4679fe6 100644 --- a/src/Worker/UpdateContact.php +++ b/src/Worker/UpdateContact.php @@ -51,6 +51,7 @@ class UpdateContact return 0; } + Logger::debug('Update contact', ['id' => $contact_id]); return Worker::add($run_parameters, 'UpdateContact', $contact_id); } } From 8345ada757764e7128fcb3319f0889c86da6b4ab Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Jan 2025 06:06:39 +0000 Subject: [PATCH 2/2] Fixed codestyle --- src/Module/Photo.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 87da6be55b..c3582ee655 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -65,19 +65,19 @@ class Photo extends BaseApi OpenWebAuth::addVisitorCookieForHTTPSigner($this->server); - $customsize = 0; + $customsize = 0; $square_resize = true; - $scale = null; - $stamp = microtime(true); + $scale = null; + $stamp = microtime(true); // User avatar if (!empty($this->parameters['type'])) { if (!empty($this->parameters['customsize'])) { - $customsize = intval($this->parameters['customsize']); + $customsize = intval($this->parameters['customsize']); $square_resize = !in_array($this->parameters['type'], ['media', 'preview']); } if (!empty($this->parameters['guid'])) { - $guid = $this->parameters['guid']; + $guid = $this->parameters['guid']; $account = DBA::selectFirst('account-user-view', ['id'], ['guid' => $guid], ['order' => ['uid' => true]]); if (empty($account)) { throw new HTTPException\NotFoundException(); @@ -92,7 +92,7 @@ class Photo extends BaseApi if (!empty($this->parameters['nickname_ext'])) { $nickname = pathinfo($this->parameters['nickname_ext'], PATHINFO_FILENAME); - $user = User::getByNickname($nickname, ['uid']); + $user = User::getByNickname($nickname, ['uid']); if (empty($user)) { throw new HTTPException\NotFoundException(); } @@ -112,9 +112,9 @@ class Photo extends BaseApi $photo = self::getPhotoById($id, $this->parameters['type'], $customsize ?: Proxy::PIXEL_SMALL); } else { $photoid = pathinfo($this->parameters['name'], PATHINFO_FILENAME); - $scale = 0; + $scale = 0; if (substr($photoid, -2, 1) == '-') { - $scale = intval(substr($photoid, -1, 1)); + $scale = intval(substr($photoid, -1, 1)); $photoid = substr($photoid, 0, -2); } @@ -176,7 +176,7 @@ class Photo extends BaseApi Logger::warning('Invalid photo', ['id' => $photo['id']]); if (in_array($photo['backend-class'], [ExternalResource::NAME])) { $reference = json_decode($photo['backend-ref'], true); - $error = DI::l10n()->t('Invalid external resource with url %s.', $reference['url']); + $error = DI::l10n()->t('Invalid external resource with url %s.', $reference['url']); } else { $error = DI::l10n()->t('Invalid photo with id %s.', $photo['id']); } @@ -230,13 +230,13 @@ class Photo extends BaseApi $output = microtime(true) - $stamp; $total = microtime(true) - $totalstamp; - $rest = $total - ($fetch + $data + $checksum + $output); + $rest = $total - ($fetch + $data + $checksum + $output); if (!is_null($scale) && ($scale < 4)) { Logger::debug('Performance:', [ - 'scale' => $scale, 'resource' => $photo['resource-id'], - 'total' => number_format($total, 3), 'fetch' => number_format($fetch, 3), - 'data' => number_format($data, 3), 'checksum' => number_format($checksum, 3), + 'scale' => $scale, 'resource' => $photo['resource-id'], + 'total' => number_format($total, 3), 'fetch' => number_format($fetch, 3), + 'data' => number_format($data, 3), 'checksum' => number_format($checksum, 3), 'output' => number_format($output, 3), 'rest' => number_format($rest, 3) ]); } @@ -298,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', 'next-update']; + $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; @@ -359,7 +359,7 @@ class Photo extends BaseApi && ($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); + $update = !$curlResult->isSuccess() && ($curlResult->getReturnCode() == 404); Logger::debug('Got return code for avatar', ['return code' => $curlResult->getReturnCode(), 'cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); } if ($update) { @@ -402,7 +402,7 @@ class Photo extends BaseApi } return MPhoto::createPhotoForExternalResource($url, 0, $mimetext, $contact['blurhash'] ?? null, $customsize, $customsize); case 'header': - $fields = ['uid', 'url', 'header', 'network', 'gsid']; + $fields = ['uid', 'url', 'header', 'network', 'gsid']; $contact = Contact::getById($id, $fields); if (empty($contact)) { return false;