Delete the cache entry when the post is changed or deleted
This commit is contained in:
parent
7c9f10e58f
commit
da658cbf1d
|
@ -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';
|
||||
|
||||
--
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" => [
|
||||
|
|
Loading…
Reference in a new issue