]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/NoScrape.php
Several performance improvements
[friendica.git] / src / Module / NoScrape.php
index 06bce3e2486d97bb4c43c40f0a1ea0267d236202..e3a01ceaab6d29467d47ceda5c4a0afc1fad9e55 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -22,6 +22,7 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
+use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
@@ -35,7 +36,9 @@ use Friendica\Model\User;
  */
 class NoScrape extends BaseModule
 {
-       public function rawContent()
+       const CACHEKEY = 'noscrape:';
+
+       protected function rawContent(array $request = [])
        {
                $a = DI::app();
 
@@ -55,6 +58,12 @@ class NoScrape extends BaseModule
                        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 = [
                        'addr'         => $owner['addr'],
                        'nick'         => $which,
@@ -122,10 +131,12 @@ class NoScrape extends BaseModule
                $profile_fields = ['about', 'locality', 'region', 'postal-code', 'country-name', 'xmpp', 'matrix'];
                foreach ($profile_fields as $field) {
                        if (!empty($owner[$field])) {
-                               $json_info["$field"] = $owner[$field];
+                               $json_info[$field] = $owner[$field];
                        }
                }
 
+               DI::cache()->set($cachekey, $json_info, Duration::DAY);
+
                System::jsonExit($json_info);
        }
 }