[CORE][Cache] Use hashmaps to store language related items

This commit is contained in:
Hugo Sales 2021-11-08 15:07:29 +00:00 committed by Diogo Peralta Cordeiro
parent 2eb31952bc
commit 68c6dd1ba9
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
1 changed files with 2 additions and 2 deletions

View File

@ -361,14 +361,14 @@ class Actor extends Entity
public function getPreferredLanguageChoices(?self $context = null): array
{
$id = $context?->getId() ?? $this->getId();
return Cache::get(
return Cache::getHashMap(
'actor-' . $this->getId() . '-langs' . (!\is_null($context) ? '-' . $context->getId() : ''),
fn () => array_merge( // TODO replace with F\transform
...F\map(DB::dql(
'select l from actor_language al join language l with al.language_id = l.id where al.actor_id = :id order by al.order ASC',
['id' => $id],
), fn ($l) => $l->toChoiceFormat()),
) ?: DB::findOneBy('language', ['locale' => Common::config('site', 'language')])->toChoiceFormat(),
) ?: Cache::getHashMapKey('languages', Common::config('site', 'language'))->toChoiceFormat(),
);
}