Commit 77124701 authored by swentel's avatar swentel

Issue #3176418: use cache

parent 347e3c60
......@@ -120,6 +120,17 @@ The default path can be overridden in settings.php via settings:
$settings['activitypub_keys_path'] = '/your/path/';
```
## Caching
For incoming or outgoing requests, information needs to be fetched to get the
inbox endpoint for example. This is saved in private://activitypub/cache
The default path and ttl can be overridden in settings.php:
```
$settings['activitypub_cache_path'] = '/your/path/';
$settings['activitypub_cache_ttl'] = 3600;
```
## Default avatar
The default avatar path can be overridden in settings.php via settings:
......
......@@ -13,18 +13,27 @@ function activitypub_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$directory = activitypub_keys_path();
if (\Drupal::hasService('stream_wrapper.private') && !is_dir($directory)) {
\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
if (!\Drupal::hasService('stream_wrapper.private') || !is_dir($directory)) {
$description = t('An automated attempt to create the directory %directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', ['%directory' => $directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']);
$requirements['activitypub keys_directory'] = [
'title' => t('ActivityPub keys directory'),
'description' => $description,
'severity' => REQUIREMENT_ERROR,
];
$directories = [
activitypub_keys_path() => t('ActivityPub keys directory'),
activitypub_cache_path() => t('ActivityPub cache directory')
];
$delta = 0;
foreach ($directories as $path => $label) {
if (\Drupal::hasService('stream_wrapper.private') && !is_dir($path)) {
\Drupal::service('file_system')->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
if (!\Drupal::hasService('stream_wrapper.private') || !is_dir($path)) {
$description = t('An automated attempt to create the directory %directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', ['%directory' => $keys_directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']);
$requirements['activitypub_directory_' . $delta] = [
'title' => $label,
'description' => $description,
'severity' => REQUIREMENT_ERROR,
];
$delta++;
}
}
}
......
......@@ -84,16 +84,34 @@ function activitypub_cron() {
/**
* Returns the path where the keys are stored.
*
* @return mixed|null
* @return string
*/
function activitypub_keys_path() {
return Settings::get('activitypub_keys_path', 'private://activitypub/keys');
}
/**
* Returns the path where the cache is stored.
*
* @return string
*/
function activitypub_cache_path() {
return Settings::get('activitypub_cache_path', 'private://activitypub/cache');
}
/**
* Returns the cache ttl.
*
* @return int
*/
function activitypub_cache_ttl() {
return Settings::get('activitypub_cache_ttl', 604800);
}
/**
* Returns the default avatar path.
*
* @return mixed|null
* @return string
*/
function activitypub_default_avatar_path() {
return Settings::get('activitypub_default_avatar_path', 'assets/avatar.png');
......
......@@ -108,7 +108,10 @@ class ActivityPubUtility implements ActivityPubUtilityInterface {
*/
public function getServer(array $config = []) {
$config += [
'cache' => ['enabled' => FALSE],
'cache' => [
'ttl' => activitypub_cache_ttl(),
'stream' => activitypub_cache_path()
],
];
$config['instance']['types'] = 'ignore';
return new Server($config);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment