]> git.mxchange.org Git - friendica.git/commitdiff
Delete the cache entry when the post is changed or deleted
authorMichael <heluecht@pirati.ca>
Tue, 6 Sep 2022 21:51:47 +0000 (21:51 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 6 Sep 2022 21:51:47 +0000 (21:51 +0000)
database.sql
doc/database/db_pagecache.md
src/Model/Item.php
src/Module/ActivityPub/Objects.php
src/Protocol/ActivityPub/PageCache.php
static/dbstructure.config.php

index d50e0bbd063da19d19820be240e0d5f7021447fc..e1ca686d47896547e0b58a196f1dbcedb826fda9 100644 (file)
@@ -1012,10 +1012,13 @@ CREATE TABLE IF NOT EXISTS `openwebauth-token` (
 --
 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 `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';
 
 --
index 6cc3edf0fd242988e27db2a375f1f59dd0cbf0ae..2be2df298d0e7c92c780468d1a6896141fba4695 100644 (file)
@@ -6,11 +6,12 @@ Stores temporary data
 Fields
 ------
 
-| Field   | Description                         | Type           | Null | Key | Default | Extra |
-| ------- | ----------------------------------- | -------------- | ---- | --- | ------- | ----- |
-| page    | Page                                | varbinary(255) | NO   | PRI | NULL    |       |
-| content | Page content                        | mediumtext     | YES  |     | NULL    |       |
-| fetched | date when the page had been fetched | datetime       | YES  |     | NULL    |       |
+| 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
 ------------
@@ -19,6 +20,13 @@ Indexes
 | ------- | ------- |
 | 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 78bc8c64d18b26410117ba65d0546db74ebb32e8..bd5591ef39ecaddf545c2587d6bc5f3b928b07de 100644 (file)
@@ -196,6 +196,8 @@ 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']);
 
@@ -319,6 +321,8 @@ 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 dc9eaaf60c46a5535b25a440eb575cace805352f..b0834929c4f132f3fb1254fe50f4c6ea1a87e935 100644 (file)
@@ -136,7 +136,7 @@ class Objects extends BaseModule
                }
 
                if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED])) {
-                       PageCache::add($_SERVER['REQUEST_URI'], $data);
+                       PageCache::add($_SERVER['REQUEST_URI'], $item['uri-id'], $data);
                }
 
                // Relaxed CORS header for public items
index d34283b152827e8b08978fd6a968752509739ec7..d9e82d713c82360cb6f61f99473799ff9ff9b48a 100644 (file)
@@ -36,17 +36,18 @@ 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, $content)
+       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, 'content' => serialize($content), 'fetched' => DateTimeFormat::utcNow()], Database::INSERT_UPDATE);
+               DBA::insert('pagecache', ['page' => $page, 'uri-id' => $uriid, 'content' => serialize($content), 'fetched' => DateTimeFormat::utcNow()], Database::INSERT_UPDATE);
 
                Logger::debug('Page added', ['page' => $page]);
        }
@@ -70,4 +71,15 @@ class PageCache
 
                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 01c593f68d828fee8208ebc470460377d84c69d0..1e7fae786feb07834dc3a97b23c0023a6b1a933e 100644 (file)
@@ -1055,12 +1055,14 @@ return [
                "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" => [