Caching of "noscrape"

This commit is contained in:
Michael 2022-05-17 15:39:04 +00:00
parent c3fd8b39aa
commit 0b50dc363b
2 changed files with 13 additions and 0 deletions

View File

@ -35,6 +35,7 @@ use Friendica\Core\Worker;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\NoScrape;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -909,6 +910,7 @@ class Contact
DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'followers:' . $uid); DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'followers:' . $uid);
DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'following:' . $uid); DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'following:' . $uid);
DI::cache()->delete(NoScrape::CACHEKEY . $uid);
} }
/** /**

View File

@ -22,6 +22,7 @@
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
@ -35,6 +36,8 @@ use Friendica\Model\User;
*/ */
class NoScrape extends BaseModule class NoScrape extends BaseModule
{ {
const CACHEKEY = 'noscrape:';
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
$a = DI::app(); $a = DI::app();
@ -55,6 +58,12 @@ class NoScrape extends BaseModule
System::jsonError(404, 'Profile not found'); System::jsonError(404, 'Profile not found');
} }
$cachekey = self::CACHEKEY . $owner['uid'];
$result = DI::cache()->get($cachekey);
if (!is_null($result)) {
System::jsonExit($result);
}
$json_info = [ $json_info = [
'addr' => $owner['addr'], 'addr' => $owner['addr'],
'nick' => $which, 'nick' => $which,
@ -126,6 +135,8 @@ class NoScrape extends BaseModule
} }
} }
DI::cache()->set($cachekey, $json_info, Duration::DAY);
System::jsonExit($json_info); System::jsonExit($json_info);
} }
} }