1
0
Fork 0

Several speed improvements (magiclink, caching, indexes)

This commit is contained in:
Michael 2021-02-17 18:59:19 +00:00
commit 312c01a517
21 changed files with 119 additions and 86 deletions

View file

@ -905,7 +905,7 @@ class Contact
if (empty($contact['uid']) || ($contact['uid'] != $uid)) {
if ($uid == 0) {
$profile_link = self::magicLink($contact['url']);
$profile_link = self::magicLinkByContact($contact);
$menu = ['profile' => [DI::l10n()->t('View Profile'), $profile_link, true]];
return $menu;
@ -2684,11 +2684,11 @@ class Contact
return 'contact/' . $contact['id'] . '/conversations';
}
if ($contact['network'] != Protocol::DFRN) {
if (!empty($contact['network']) && $contact['network'] != Protocol::DFRN) {
return $destination;
}
if (!empty($contact['uid'])) {
if (!empty($contact['uid']) || empty($contact['network'])) {
return self::magicLink($contact['url'], $url);
}
@ -2819,22 +2819,22 @@ class Contact
}
/**
* Returns a random, global contact of the current node
* Returns a random, global contact array of the current node
*
* @return string The profile URL
* @return array The profile array
* @throws Exception
*/
public static function getRandomUrl()
public static function getRandomContact()
{
$r = DBA::selectFirst('contact', ['url'], [
$contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'uid'], [
"`uid` = ? AND `network` = ? AND NOT `failed` AND `last-item` > ?",
0, Protocol::DFRN, DateTimeFormat::utc('now - 1 month'),
], ['order' => ['RAND()']]);
if (DBA::isResult($r)) {
return $r['url'];
if (DBA::isResult($contact)) {
return $contact;
}
return '';
return [];
}
}

View file

@ -930,7 +930,9 @@ class Event
$location = self::locationToArray($item['event-location']);
// Construct the profile link (magic-auth).
$profile_link = Contact::magicLinkById($item['author-id']);
$author = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$profile_link = Contact::magicLinkByContact($author);
$tpl = Renderer::getMarkupTemplate('event_stream_item.tpl');
$return = Renderer::replaceMacros($tpl, [

View file

@ -32,7 +32,6 @@ use Friendica\Core\System;
use Friendica\Model\Tag;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Protocol\Activity;
@ -75,12 +74,12 @@ class Item
'uid', 'id', 'parent', 'guid', 'network', 'gravity',
'uri-id', 'uri', 'thr-parent-id', 'thr-parent', 'parent-uri-id', 'parent-uri',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
'wall', 'private', 'starred', 'origin', 'title', 'body', 'language',
'wall', 'private', 'starred', 'origin', 'parent-origin', 'title', 'body', 'language',
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network',
'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type',
'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type', 'causer-network',
'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
'writable', 'self', 'cid', 'alias',
'event-created', 'event-edited', 'event-start', 'event-finish',
@ -2196,7 +2195,8 @@ class Item
$params = ['order' => ['received' => false]];
$thread = Post::selectFirst(['received'], $condition, $params);
if (DBA::isResult($thread)) {
return substr(DateTimeFormat::local($thread['received']), 0, 10);
$postdate = substr(DateTimeFormat::local($thread['received']), 0, 10);
return $postdate;
}
return false;
}
@ -2673,7 +2673,9 @@ class Item
foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
$mime = $attachment['mimetype'];
$the_url = Contact::magicLinkById($item['author-id'], $attachment['url']);
$author = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$the_url = Contact::magicLinkByContact($author, $attachment['url']);
if (strpos($mime, 'video') !== false) {
if (!$vhead) {

View file

@ -539,7 +539,7 @@ class Profile
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
$rr['link'] = Contact::magicLink($rr['url']);
$rr['link'] = Contact::magicLinkById($rr['cid']);
$rr['title'] = $rr['name'];
$rr['date'] = DI::l10n()->getDay(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
$rr['startime'] = null;

View file

@ -407,7 +407,7 @@ class Tag
$searchpath = DI::baseUrl() . "/search?tag=";
$taglist = DBA::select('tag-view', ['type', 'name', 'url'],
$taglist = DBA::select('tag-view', ['type', 'name', 'url', 'cid'],
['uri-id' => $item['uri-id'], 'type' => [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
while ($tag = DBA::fetch($taglist)) {
if ($tag['url'] == '') {
@ -428,7 +428,11 @@ class Tag
break;
case self::MENTION:
case self::EXCLUSIVE_MENTION:
if (!empty($tag['cid'])) {
$tag['url'] = Contact::magicLinkById($tag['cid']);
} else {
$tag['url'] = Contact::magicLink($tag['url']);
}
$return['mentions'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
$return['tags'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
break;