mirror of
https://github.com/friendica/friendica
synced 2024-12-24 12:40:16 +00:00
Merge pull request #7598 from annando/fix-picture-detection
Fix cache key problem / avoid need for fetching own pictures
This commit is contained in:
commit
39a4a3cd5f
1 changed files with 61 additions and 46 deletions
|
@ -1056,7 +1056,8 @@ class BBCode extends BaseObject
|
||||||
|
|
||||||
private static function removePictureLinksCallback($match)
|
private static function removePictureLinksCallback($match)
|
||||||
{
|
{
|
||||||
$text = Cache::get($match[1]);
|
$cache_key = 'remove:' . $match[1];
|
||||||
|
$text = Cache::get($cache_key);
|
||||||
|
|
||||||
if (is_null($text)) {
|
if (is_null($text)) {
|
||||||
$a = self::getApp();
|
$a = self::getApp();
|
||||||
|
@ -1098,7 +1099,7 @@ class BBCode extends BaseObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Cache::set($match[1], $text);
|
Cache::set($cache_key, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
|
@ -1115,11 +1116,26 @@ class BBCode extends BaseObject
|
||||||
|
|
||||||
private static function cleanPictureLinksCallback($match)
|
private static function cleanPictureLinksCallback($match)
|
||||||
{
|
{
|
||||||
$text = Cache::get($match[1]);
|
|
||||||
|
|
||||||
if (is_null($text)) {
|
|
||||||
$a = self::getApp();
|
$a = self::getApp();
|
||||||
|
|
||||||
|
// When the picture link is the own photo path then we can avoid fetching the link
|
||||||
|
$own_photo_url = preg_quote(Strings::normaliseLink($a->getBaseURL()) . '/photos/');
|
||||||
|
if (preg_match('|' . $own_photo_url . '.*?/image/|', Strings::normaliseLink($match[1]))) {
|
||||||
|
if (!empty($match[3])) {
|
||||||
|
$text = "[img=" . str_replace('-1.', '-0.', $match[2]) . "]" . $match[3] . "[/img]";
|
||||||
|
} else {
|
||||||
|
$text = "[img]" . str_replace('-1.', '-0.', $match[2]) . "[/img]";
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache_key = 'clean:' . $match[1];
|
||||||
|
$text = Cache::get($cache_key);
|
||||||
|
if (!is_null($text)) {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only fetch the header, not the content
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
|
|
||||||
$ch = @curl_init($match[1]);
|
$ch = @curl_init($match[1]);
|
||||||
|
@ -1165,8 +1181,7 @@ class BBCode extends BaseObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Cache::set($match[1], $text);
|
Cache::set($cache_key, $text);
|
||||||
}
|
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue