New option to activate/deactivate contact avatar cache

This commit is contained in:
Michael 2021-10-23 17:18:30 +00:00
parent e0411743e2
commit 8185c591d8
5 changed files with 64 additions and 44 deletions

View File

@ -1553,18 +1553,22 @@ class Contact
*/ */
public static function checkAvatarCache(int $cid) public static function checkAvatarCache(int $cid)
{ {
$contact = DBA::selectFirst('contact', ['url', 'avatar', 'photo', 'thumb', 'micro'], ['id' => $cid, 'uid' => 0, 'self' => false]); $contact = DBA::selectFirst('contact', ['url', 'network', 'avatar', 'photo', 'thumb', 'micro'], ['id' => $cid, 'uid' => 0, 'self' => false]);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
return; return;
} }
if (empty($contact['avatar']) || (!empty($contact['photo']) && !empty($contact['thumb']) && !empty($contact['micro']))) { if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || DI::config()->get('system', 'cache_contact_avatar')) {
if (!empty($contact['avatar']) && (empty($contact['photo']) || empty($contact['thumb']) || empty($contact['micro']))) {
Logger::info('Adding avatar cache', ['id' => $cid, 'contact' => $contact]);
self::updateAvatar($cid, $contact['avatar'], true);
return; return;
} }
} elseif (!empty($contact['photo']) || !empty($contact['thumb']) || !empty($contact['micro'])) {
Logger::info('Adding avatar cache', ['id' => $cid, 'contact' => $contact]); Logger::info('Removing avatar cache', ['id' => $cid, 'contact' => $contact]);
self::updateAvatar($cid, $contact['avatar'], true); self::updateAvatar($cid, $contact['avatar'], true);
return;
}
} }
/** /**
@ -1868,6 +1872,7 @@ class Contact
$avatar = self::getDefaultAvatar($contact, Proxy::SIZE_SMALL); $avatar = self::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
} }
if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || DI::config()->get('system', 'cache_contact_avatar')) {
if ($default_avatar && Proxy::isLocalImage($avatar)) { if ($default_avatar && Proxy::isLocalImage($avatar)) {
$fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(), $fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(),
'photo' => $avatar, 'photo' => $avatar,
@ -1917,6 +1922,12 @@ class Contact
} else { } else {
$update = ($fields['photo'] . $fields['thumb'] . $fields['micro'] != $contact['photo'] . $contact['thumb'] . $contact['micro']) || $force; $update = ($fields['photo'] . $fields['thumb'] . $fields['micro'] != $contact['photo'] . $contact['thumb'] . $contact['micro']) || $force;
} }
} else {
Photo::delete(['uid' => $uid, 'contact-id' => $cid, 'photo-type' => Photo::CONTACT_AVATAR]);
$fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(),
'photo' => '', 'thumb' => '', 'micro' => ''];
$update = ($avatar != $contact['avatar'] . $contact['photo'] . $contact['thumb'] . $contact['micro']) || $force;
}
if (!$update) { if (!$update) {
return; return;

View File

@ -163,6 +163,7 @@ class Site extends BaseAdmin
$allow_users_remote_self = !empty($_POST['allow_users_remote_self']); $allow_users_remote_self = !empty($_POST['allow_users_remote_self']);
$explicit_content = !empty($_POST['explicit_content']); $explicit_content = !empty($_POST['explicit_content']);
$proxify_content = !empty($_POST['proxify_content']); $proxify_content = !empty($_POST['proxify_content']);
$cache_contact_avatar = !empty($_POST['cache_contact_avatar']);
$enable_multi_reg = !empty($_POST['enable_multi_reg']); $enable_multi_reg = !empty($_POST['enable_multi_reg']);
$enable_openid = !empty($_POST['enable_openid']); $enable_openid = !empty($_POST['enable_openid']);
@ -330,6 +331,7 @@ class Site extends BaseAdmin
DI::config()->set('system', 'allow_users_remote_self', $allow_users_remote_self); DI::config()->set('system', 'allow_users_remote_self', $allow_users_remote_self);
DI::config()->set('system', 'explicit_content' , $explicit_content); DI::config()->set('system', 'explicit_content' , $explicit_content);
DI::config()->set('system', 'proxify_content' , $proxify_content); DI::config()->set('system', 'proxify_content' , $proxify_content);
DI::config()->set('system', 'cache_contact_avatar' , $cache_contact_avatar);
DI::config()->set('system', 'check_new_version_url' , $check_new_version_url); DI::config()->set('system', 'check_new_version_url' , $check_new_version_url);
DI::config()->set('system', 'block_extended_register', !$enable_multi_reg); DI::config()->set('system', 'block_extended_register', !$enable_multi_reg);
@ -554,6 +556,7 @@ class Site extends BaseAdmin
'$disable_embedded' => ['disable_embedded', DI::l10n()->t('Don\'t embed private images in posts'), DI::config()->get('system', 'disable_embedded'), DI::l10n()->t('Don\'t replace locally-hosted private photos in posts with an embedded copy of the image. This means that contacts who receive posts containing private photos will have to authenticate and load each image, which may take a while.')], '$disable_embedded' => ['disable_embedded', DI::l10n()->t('Don\'t embed private images in posts'), DI::config()->get('system', 'disable_embedded'), DI::l10n()->t('Don\'t replace locally-hosted private photos in posts with an embedded copy of the image. This means that contacts who receive posts containing private photos will have to authenticate and load each image, which may take a while.')],
'$explicit_content' => ['explicit_content', DI::l10n()->t('Explicit Content'), DI::config()->get('system', 'explicit_content'), DI::l10n()->t('Set this to announce that your node is used mostly for explicit content that might not be suited for minors. This information will be published in the node information and might be used, e.g. by the global directory, to filter your node from listings of nodes to join. Additionally a note about this will be shown at the user registration page.')], '$explicit_content' => ['explicit_content', DI::l10n()->t('Explicit Content'), DI::config()->get('system', 'explicit_content'), DI::l10n()->t('Set this to announce that your node is used mostly for explicit content that might not be suited for minors. This information will be published in the node information and might be used, e.g. by the global directory, to filter your node from listings of nodes to join. Additionally a note about this will be shown at the user registration page.')],
'$proxify_content' => ['proxify_content', DI::l10n()->t('Proxify external content'), DI::config()->get('system', 'proxify_content'), DI::l10n()->t('Route external content via the proxy functionality. This is used for example for some OEmbed accesses and in some other rare cases.')], '$proxify_content' => ['proxify_content', DI::l10n()->t('Proxify external content'), DI::config()->get('system', 'proxify_content'), DI::l10n()->t('Route external content via the proxy functionality. This is used for example for some OEmbed accesses and in some other rare cases.')],
'$cache_contact_avatar' => ['cache_contact_avatar', DI::l10n()->t('Cache contact avatars'), DI::config()->get('system', 'cache_contact_avatar'), DI::l10n()->t('Locally store the avatar pictures of the contacts. This uses a lot of storage space but it increases the performance.')],
'$allow_users_remote_self'=> ['allow_users_remote_self', DI::l10n()->t('Allow Users to set remote_self'), DI::config()->get('system', 'allow_users_remote_self'), DI::l10n()->t('With checking this, every user is allowed to mark every contact as a remote_self in the repair contact dialog. Setting this flag on a contact causes mirroring every posting of that contact in the users stream.')], '$allow_users_remote_self'=> ['allow_users_remote_self', DI::l10n()->t('Allow Users to set remote_self'), DI::config()->get('system', 'allow_users_remote_self'), DI::l10n()->t('With checking this, every user is allowed to mark every contact as a remote_self in the repair contact dialog. Setting this flag on a contact causes mirroring every posting of that contact in the users stream.')],
'$enable_multi_reg' => ['enable_multi_reg', DI::l10n()->t('Enable multiple registrations'), !DI::config()->get('system', 'block_extended_register'), DI::l10n()->t('Enable users to register additional accounts for use as pages.')], '$enable_multi_reg' => ['enable_multi_reg', DI::l10n()->t('Enable multiple registrations'), !DI::config()->get('system', 'block_extended_register'), DI::l10n()->t('Enable users to register additional accounts for use as pages.')],
'$enable_openid' => ['enable_openid', DI::l10n()->t('Enable OpenID'), !DI::config()->get('system', 'no_openid'), DI::l10n()->t('Enable OpenID support for registration and logins.')], '$enable_openid' => ['enable_openid', DI::l10n()->t('Enable OpenID'), !DI::config()->get('system', 'no_openid'), DI::l10n()->t('Enable OpenID support for registration and logins.')],

View File

@ -64,6 +64,10 @@ return [
// Themes users can change to in their settings. // Themes users can change to in their settings.
'allowed_themes' => 'frio,quattro,vier,duepuntozero,smoothly', 'allowed_themes' => 'frio,quattro,vier,duepuntozero,smoothly',
// cache_contact_avatar (Boolean)
// Cache versions of the contact avatars. Uses a lot of storage space
'cache_contact_avatar' => true,
// curl_timeout (Integer) // curl_timeout (Integer)
// Value is in seconds. Set to 0 for unlimited (not recommended). // Value is in seconds. Set to 0 for unlimited (not recommended).
'curl_timeout' => 60, 'curl_timeout' => 60,

View File

@ -116,6 +116,7 @@
{{include file="field_input.tpl" field=$dbclean_unclaimed}} {{include file="field_input.tpl" field=$dbclean_unclaimed}}
{{include file="field_input.tpl" field=$dbclean_expire_conv}} {{include file="field_input.tpl" field=$dbclean_expire_conv}}
{{include file="field_checkbox.tpl" field=$optimize_tables}} {{include file="field_checkbox.tpl" field=$optimize_tables}}
{{include file="field_checkbox.tpl" field=$cache_contact_avatar}}
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div> <div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
<h2>{{$worker_title}}</h2> <h2>{{$worker_title}}</h2>

View File

@ -251,6 +251,7 @@
{{include file="field_input.tpl" field=$dbclean_unclaimed}} {{include file="field_input.tpl" field=$dbclean_unclaimed}}
{{include file="field_input.tpl" field=$dbclean_expire_conv}} {{include file="field_input.tpl" field=$dbclean_expire_conv}}
{{include file="field_checkbox.tpl" field=$optimize_tables}} {{include file="field_checkbox.tpl" field=$optimize_tables}}
{{include file="field_checkbox.tpl" field=$cache_contact_avatar}}
</div> </div>
<div class="panel-footer"> <div class="panel-footer">
<input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/> <input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/>