Avoid locally probing last item via network

This commit is contained in:
Michael 2020-08-19 04:45:31 +00:00
parent 29494ea721
commit eb95314aaa
2 changed files with 13 additions and 0 deletions

View file

@ -164,6 +164,11 @@ class User
*/ */
public static function getIdForURL(string $url) public static function getIdForURL(string $url)
{ {
// Avoid any database requests when the hostname isn't even part of the url.
if (!strpos($url, DI::baseUrl()->getHostname())) {
return 0;
}
$self = Contact::selectFirst(['uid'], ['self' => true, 'nurl' => Strings::normaliseLink($url)]); $self = Contact::selectFirst(['uid'], ['self' => true, 'nurl' => Strings::normaliseLink($url)]);
if (!empty($self['uid'])) { if (!empty($self['uid'])) {
return $self['uid']; return $self['uid'];

View file

@ -2012,6 +2012,14 @@ class Probe
*/ */
public static function getLastUpdate(array $data) public static function getLastUpdate(array $data)
{ {
$uid = User::getIdForURL($data['url']);
if (!empty($uid)) {
$contact = Contact::selectFirst(['url', 'last-item'], ['self' => true, 'uid' => $uid]);
if (!empty($contact['last-item'])) {
return $contact['last-item'];
}
}
if ($lastUpdate = self::updateFromNoScrape($data)) { if ($lastUpdate = self::updateFromNoScrape($data)) {
return $lastUpdate; return $lastUpdate;
} }