--
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';
--
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
------------
| ------- | ------- |
| 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)
$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']);
// 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)
}
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
* 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]);
}
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]);
+ }
}
"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" => [