]> git.mxchange.org Git - friendica.git/commitdiff
Use the cached activity function
authorMichael <heluecht@pirati.ca>
Wed, 7 Sep 2022 19:46:24 +0000 (19:46 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 7 Sep 2022 19:46:24 +0000 (19:46 +0000)
database.sql
doc/database.md
doc/database/db_pagecache.md [deleted file]
src/Model/Item.php
src/Module/ActivityPub/Objects.php
src/Protocol/ActivityPub/PageCache.php [deleted file]
src/Protocol/ActivityPub/Transmitter.php
src/Worker/OptimizeTables.php
static/dbstructure.config.php
static/defaults.config.php

index e1ca686d47896547e0b58a196f1dbcedb826fda9..3503efd15d6b69de05c9db0cf72c61aba5ff1979 100644 (file)
@@ -1007,20 +1007,6 @@ CREATE TABLE IF NOT EXISTS `openwebauth-token` (
        FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts';
 
---
--- TABLE pagecache
---
-CREATE TABLE IF NOT EXISTS `pagecache` (
-       `page` varbinary(255) NOT NULL COMMENT 'Page',
-       `uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the uri the page belongs to',
-       `content` mediumtext COMMENT 'Page content',
-       `fetched` datetime COMMENT 'date when the page had been fetched',
-        PRIMARY KEY(`page`),
-        INDEX `fetched` (`fetched`),
-        INDEX `uri-id` (`uri-id`),
-       FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
-) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Stores temporary data';
-
 --
 -- TABLE parsed_url
 --
index 1a01df337c434f00263b4ab84eb7013bc18cc183..5aed24e91a4eca77f224fb741859141ee88a2b6d 100644 (file)
@@ -47,7 +47,6 @@ Database Tables
 | [notify-threads](help/database/db_notify-threads) |  |
 | [oembed](help/database/db_oembed) | cache for OEmbed queries |
 | [openwebauth-token](help/database/db_openwebauth-token) | Store OpenWebAuth token to verify contacts |
-| [pagecache](help/database/db_pagecache) | Stores temporary data |
 | [parsed_url](help/database/db_parsed_url) | cache for 'parse_url' queries |
 | [pconfig](help/database/db_pconfig) | personal (per user) configuration storage |
 | [permissionset](help/database/db_permissionset) |  |
diff --git a/doc/database/db_pagecache.md b/doc/database/db_pagecache.md
deleted file mode 100644 (file)
index 2be2df2..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-Table pagecache
-===========
-
-Stores temporary data
-
-Fields
-------
-
-| Field   | Description                                                        | Type           | Null | Key | Default | Extra |
-| ------- | ------------------------------------------------------------------ | -------------- | ---- | --- | ------- | ----- |
-| page    | Page                                                               | varbinary(255) | NO   | PRI | NULL    |       |
-| uri-id  | Id of the item-uri table that contains the uri the page belongs to | int unsigned   | YES  |     | NULL    |       |
-| content | Page content                                                       | mediumtext     | YES  |     | NULL    |       |
-| fetched | date when the page had been fetched                                | datetime       | YES  |     | NULL    |       |
-
-Indexes
-------------
-
-| Name    | Fields  |
-| ------- | ------- |
-| PRIMARY | page    |
-| fetched | fetched |
-| uri-id  | uri-id  |
-
-Foreign Keys
-------------
-
-| Field | Target Table | Target Field |
-|-------|--------------|--------------|
-| uri-id | [item-uri](help/database/db_item-uri) | id |
-
-Return to [database documentation](help/database)
index bd5591ef39ecaddf545c2587d6bc5f3b928b07de..78bc8c64d18b26410117ba65d0546db74ebb32e8 100644 (file)
@@ -196,8 +196,6 @@ class Item
                $notify_items = [];
 
                while ($item = DBA::fetch($items)) {
-                       ActivityPub\PageCache::deleteByUriId($item['uri-id']);
-
                        if (!empty($fields['body'])) {
                                Post\Media::insertFromAttachmentData($item['uri-id'], $fields['body']);
 
@@ -321,8 +319,6 @@ class Item
                // clean up categories and tags so they don't end up as orphans
                Post\Category::deleteByURIId($item['uri-id'], $item['uid']);
 
-               ActivityPub\PageCache::deleteByUriId($item['uri-id']);
-
                /*
                 * If item is a link to a photo resource, nuke all the associated photos
                 * (visitors will not have photo resources)
index b0834929c4f132f3fb1254fe50f4c6ea1a87e935..96b3f638e789660df8790608e392712b78ca3914 100644 (file)
@@ -31,7 +31,6 @@ use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\ActivityPub;
-use Friendica\Protocol\ActivityPub\PageCache;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
@@ -51,13 +50,6 @@ class Objects extends BaseModule
                        DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString()));
                }
 
-               $data = PageCache::fetch($_SERVER['REQUEST_URI']);
-               if (!empty($data)) {
-                       header('Access-Control-Allow-Origin: *');
-
-                       System::jsonExit($data, 'application/activity+json');
-               }
-
                $itemuri = DBA::selectFirst('item-uri', ['id'], ['guid' => $this->parameters['guid']]);
 
                if (DBA::isResult($itemuri)) {
@@ -106,7 +98,7 @@ class Objects extends BaseModule
                Network::checkEtagModified($etag, $last_modified);
 
                if (empty($this->parameters['activity']) && ($item['gravity'] != GRAVITY_ACTIVITY)) {
-                       $activity = ActivityPub\Transmitter::createActivityFromItem($item['id'], true);
+                       $activity = ActivityPub\Transmitter::createCachedActivityFromItem($item['id'], false, true);
                        if (empty($activity['type'])) {
                                throw new HTTPException\NotFoundException();
                        }
@@ -123,7 +115,7 @@ class Objects extends BaseModule
                } elseif (empty($this->parameters['activity']) || in_array($this->parameters['activity'],
                        ['Create', 'Announce', 'Update', 'Like', 'Dislike', 'Accept', 'Reject',
                        'TentativeAccept', 'Follow', 'Add'])) {
-                       $data = ActivityPub\Transmitter::createActivityFromItem($item['id']);
+                       $data = ActivityPub\Transmitter::createCachedActivityFromItem($item['id']);
                        if (empty($data)) {
                                throw new HTTPException\NotFoundException();
                        }
@@ -135,10 +127,6 @@ class Objects extends BaseModule
                        throw new HTTPException\NotFoundException();
                }
 
-               if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED])) {
-                       PageCache::add($_SERVER['REQUEST_URI'], $item['uri-id'], $data);
-               }
-
                // Relaxed CORS header for public items
                header('Access-Control-Allow-Origin: *');
 
diff --git a/src/Protocol/ActivityPub/PageCache.php b/src/Protocol/ActivityPub/PageCache.php
deleted file mode 100644 (file)
index d9e82d7..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Protocol\ActivityPub;
-
-use Friendica\Core\Logger;
-use Friendica\Database\Database;
-use Friendica\Database\DBA;
-use Friendica\DI;
-use Friendica\Util\DateTimeFormat;
-
-/**
- * This class handles the page cache
- */
-class PageCache
-{
-       /**
-        * Add content to the page cache
-        *
-        * @param string $page
-        * @param int    $uriid
-        * @param mixed $content
-        * @return void
-        */
-       public static function add(string $page, int $uriid, $content)
-       {
-               if (!DI::config()->get('system', 'pagecache')) {
-                       return;
-               }
-
-               DBA::delete('pagecache', ["`fetched` < ?", DateTimeFormat::utc('now - 5 minutes')]);
-               DBA::insert('pagecache', ['page' => $page, 'uri-id' => $uriid, 'content' => serialize($content), 'fetched' => DateTimeFormat::utcNow()], Database::INSERT_UPDATE);
-
-               Logger::debug('Page added', ['page' => $page]);
-       }
-
-       /**
-        * Fetch data from the page cache
-        *
-        * @param string $page
-        * @return mixed
-        */
-       public static function fetch(string $page)
-       {
-               $pagecache = DBA::selectFirst('pagecache', [], ['page' => $page]);
-               if (empty($pagecache['content'])) {
-                       return null;
-               }
-
-               DBA::update('pagecache', ['fetched' => DateTimeFormat::utcNow()], ['page' => $page]);
-
-               Logger::debug('Page fetched', ['page' => $page]);
-
-               return unserialize($pagecache['content']);
-       }
-
-       /**
-        * Delete the pagecache via its connected uri-id
-        *
-        * @param integer $uriid
-        * @return void
-        */
-       public static function deleteByUriId(int $uriid)
-       {
-               DBA::delete('pagecache', ['uri-id' => $uriid]);
-       }
-}
index 18d0cc65f2f83449d8496cc631b7daf4404a9acb..162745c396e17516355351813d5f23a24a0ab9d3 100644 (file)
@@ -1185,9 +1185,9 @@ class Transmitter
         * @return array|false activity or false on failure
         * @throws \Exception
         */
-       public static function createCachedActivityFromItem(int $item_id, bool $force = false)
+       public static function createCachedActivityFromItem(int $item_id, bool $force = false, bool $object_mode = false)
        {
-               $cachekey = 'APDelivery:createActivity:' . $item_id;
+               $cachekey = 'APDelivery:createActivity:' . $item_id . ':' . (int)$object_mode;
 
                if (!$force) {
                        $data = DI::cache()->get($cachekey);
@@ -1196,7 +1196,7 @@ class Transmitter
                        }
                }
 
-               $data = self::createActivityFromItem($item_id);
+               $data = self::createActivityFromItem($item_id, $object_mode);
 
                DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR);
                return $data;
index cfe8295aac310d55683cfcb150c175494405acba..cfbdca7fe5f6390074273be833ff62ab1c692ebf 100644 (file)
@@ -43,7 +43,6 @@ class OptimizeTables
                DBA::e("OPTIMIZE TABLE `cache`");
                DBA::e("OPTIMIZE TABLE `locks`");
                DBA::e("OPTIMIZE TABLE `oembed`");
-               DBA::e("OPTIMIZE TABLE `pagecache`");
                DBA::e("OPTIMIZE TABLE `parsed_url`");
                DBA::e("OPTIMIZE TABLE `session`");
 
index 1e7fae786feb07834dc3a97b23c0023a6b1a933e..9f1ab158589875cffac1be87f5723685cec5235d 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1483);
+       define('DB_UPDATE_VERSION', 1482);
 }
 
 return [
@@ -1051,20 +1051,6 @@ return [
                        "uid" => ["uid"],
                ]
        ],
-       "pagecache" => [
-               "comment" => "Stores temporary data",
-               "fields" => [
-                       "page" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "Page"],
-                       "uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the uri the page belongs to"],
-                       "content" => ["type" => "mediumtext", "comment" => "Page content"],
-                       "fetched" => ["type" => "datetime", "comment" => "date when the page had been fetched"],
-               ],
-               "indexes" => [
-                       "PRIMARY" => ["page"],
-                       "fetched" => ["fetched"],
-                       "uri-id" => ["uri-id"],
-               ],
-       ],
        "parsed_url" => [
                "comment" => "cache for 'parse_url' queries",
                "fields" => [
index bfd2f8d44ced9821ffcce966f44487426d45983e..7625de0bd4fcb096e7484c1d76a97e2ce7286595 100644 (file)
@@ -478,10 +478,6 @@ return [
                // Don't show smilies.
                'no_smilies' => false,
 
-               // pagecache (Boolean)
-               // Cache frequently fetched pages.
-               'pagecache' => false,
-
                // paranoia (Boolean)
                // Log out users if their IP address changed.
                'paranoia' => false,