Merge pull request #11892 from annando/pagecache
Pagecache for frequently fetched pages
This commit is contained in:
commit
7da43fe28a
7 changed files with 16 additions and 29 deletions
|
@ -3321,7 +3321,7 @@ class Contact
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$contact = self::getByURL($url, false, ['id', 'updated']);
|
$contact = self::getByURL($url, false, ['id', 'updated']);
|
||||||
if (empty($contact['id'])) {
|
if (empty($contact['id']) && Network::isValidHttpUrl($url)) {
|
||||||
Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);
|
Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);
|
||||||
++$added;
|
++$added;
|
||||||
} elseif ($contact['updated'] < DateTimeFormat::utc('now -7 days')) {
|
} elseif ($contact['updated'] < DateTimeFormat::utc('now -7 days')) {
|
||||||
|
|
|
@ -21,8 +21,10 @@
|
||||||
|
|
||||||
namespace Friendica\Model;
|
namespace Friendica\Model;
|
||||||
|
|
||||||
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\DI;
|
||||||
|
|
||||||
class ItemURI
|
class ItemURI
|
||||||
{
|
{
|
||||||
|
@ -35,14 +37,16 @@ class ItemURI
|
||||||
*/
|
*/
|
||||||
public static function insert(array $fields)
|
public static function insert(array $fields)
|
||||||
{
|
{
|
||||||
|
$fields = DI::dbaDefinition()->truncateFieldsForTable('item-uri', $fields);
|
||||||
|
|
||||||
if (!DBA::exists('item-uri', ['uri' => $fields['uri']])) {
|
if (!DBA::exists('item-uri', ['uri' => $fields['uri']])) {
|
||||||
DBA::insert('item-uri', $fields, Database::INSERT_UPDATE);
|
DBA::insert('item-uri', $fields, Database::INSERT_IGNORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemuri = DBA::selectFirst('item-uri', ['id', 'guid'], ['uri' => $fields['uri']]);
|
$itemuri = DBA::selectFirst('item-uri', ['id', 'guid'], ['uri' => $fields['uri']]);
|
||||||
|
|
||||||
if (!DBA::isResult($itemuri)) {
|
if (!DBA::isResult($itemuri)) {
|
||||||
// This shouldn't happen
|
// This shouldn't happen
|
||||||
|
Logger::warning('Item-uri not found', $fields);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,22 +81,4 @@ class ItemURI
|
||||||
|
|
||||||
return $itemuri['id'] ?? 0;
|
return $itemuri['id'] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Searched for an id of a given guid.
|
|
||||||
*
|
|
||||||
* @param string $guid
|
|
||||||
* @return integer item-uri id
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public static function getIdByGUID(string $guid): int
|
|
||||||
{
|
|
||||||
$itemuri = DBA::selectFirst('item-uri', ['id'], ['guid' => $guid]);
|
|
||||||
|
|
||||||
if (!DBA::isResult($itemuri)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $itemuri['id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ class Objects extends BaseModule
|
||||||
Network::checkEtagModified($etag, $last_modified);
|
Network::checkEtagModified($etag, $last_modified);
|
||||||
|
|
||||||
if (empty($this->parameters['activity']) && ($item['gravity'] != GRAVITY_ACTIVITY)) {
|
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'])) {
|
if (empty($activity['type'])) {
|
||||||
throw new HTTPException\NotFoundException();
|
throw new HTTPException\NotFoundException();
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class Objects extends BaseModule
|
||||||
} elseif (empty($this->parameters['activity']) || in_array($this->parameters['activity'],
|
} elseif (empty($this->parameters['activity']) || in_array($this->parameters['activity'],
|
||||||
['Create', 'Announce', 'Update', 'Like', 'Dislike', 'Accept', 'Reject',
|
['Create', 'Announce', 'Update', 'Like', 'Dislike', 'Accept', 'Reject',
|
||||||
'TentativeAccept', 'Follow', 'Add'])) {
|
'TentativeAccept', 'Follow', 'Add'])) {
|
||||||
$data = ActivityPub\Transmitter::createActivityFromItem($item['id']);
|
$data = ActivityPub\Transmitter::createCachedActivityFromItem($item['id']);
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
throw new HTTPException\NotFoundException();
|
throw new HTTPException\NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ use Friendica\Model\Verb;
|
||||||
use Friendica\Module\BaseSettings;
|
use Friendica\Module\BaseSettings;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
|
use Friendica\Util\Network;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
use Friendica\Worker\Delivery;
|
use Friendica\Worker\Delivery;
|
||||||
|
|
||||||
|
@ -373,7 +374,7 @@ class Account extends BaseSettings
|
||||||
// or the handle of the account, therefore we check for either
|
// or the handle of the account, therefore we check for either
|
||||||
// "http" or "@" to be present in the string.
|
// "http" or "@" to be present in the string.
|
||||||
// All other fields from the row will be ignored
|
// All other fields from the row will be ignored
|
||||||
if ((strpos($csvRow[0], '@') !== false) || in_array(parse_url($csvRow[0], PHP_URL_SCHEME), ['http', 'https'])) {
|
if ((strpos($csvRow[0], '@') !== false) || Network::isValidHttpUrl($csvRow[0])) {
|
||||||
Worker::add(PRIORITY_MEDIUM, 'AddContact', local_user(), $csvRow[0]);
|
Worker::add(PRIORITY_MEDIUM, 'AddContact', local_user(), $csvRow[0]);
|
||||||
} else {
|
} else {
|
||||||
Logger::notice('Invalid account', ['url' => $csvRow[0]]);
|
Logger::notice('Invalid account', ['url' => $csvRow[0]]);
|
||||||
|
|
|
@ -1185,9 +1185,9 @@ class Transmitter
|
||||||
* @return array|false activity or false on failure
|
* @return array|false activity or false on failure
|
||||||
* @throws \Exception
|
* @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) {
|
if (!$force) {
|
||||||
$data = DI::cache()->get($cachekey);
|
$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);
|
DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR);
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
@ -643,7 +643,7 @@ return [
|
||||||
'worker_load_exponent' => 3,
|
'worker_load_exponent' => 3,
|
||||||
|
|
||||||
// worker_processes_cooldown (Integer)
|
// worker_processes_cooldown (Integer)
|
||||||
// Maximum number pro processes that causes a cooldown before each worker function call.
|
// Maximum number per processes that causes a cooldown before each worker function call.
|
||||||
'worker_processes_cooldown' => 0,
|
'worker_processes_cooldown' => 0,
|
||||||
|
|
||||||
// worker_multiple_fetch (Boolean)
|
// worker_multiple_fetch (Boolean)
|
||||||
|
|
Loading…
Reference in a new issue