fix(cache): suffix cache names with authenticated for credits, map and pages

This commit is contained in:
Yassine Doghri 2022-01-23 19:00:08 +00:00
parent 18ae557e97
commit 418a70b2a6
13 changed files with 48 additions and 33 deletions

View File

@ -20,9 +20,12 @@ class CreditsController extends BaseController
{
$locale = service('request')
->getLocale();
$allPodcasts = (new PodcastModel())->findAll();
$cacheName = "page_credits_{$locale}";
$cacheName = implode(
'_',
array_filter(['page', 'credits', $locale, can_user_interact() ? 'authenticated' : null]),
);
if (! ($found = cache($cacheName))) {
$page = new Page([
'title' => lang('Person.credits', [], $locale),
@ -30,6 +33,7 @@ class CreditsController extends BaseController
'content_markdown' => '',
]);
$allPodcasts = (new PodcastModel())->findAll();
$allCredits = (new CreditModel())->findAll();
// Unlike the carpenter, we make a tree from a table:

View File

@ -90,7 +90,7 @@ class EpisodeCommentController extends BaseController
"comment#{$this->comment->id}",
service('request')
->getLocale(),
can_user_interact() ? '_authenticated' : null,
can_user_interact() ? 'authenticated' : null,
]),
);

View File

@ -17,9 +17,17 @@ class MapController extends BaseController
{
public function index(): string
{
$locale = service('request')
->getLocale();
$cacheName = "page_map_{$locale}";
$cacheName = implode(
'_',
array_filter([
'page',
'map',
service('request')
->getLocale(),
can_user_interact() ? 'authenticated' : null,
]),
);
if (! ($found = cache($cacheName))) {
$found = view('pages/map', [], [
'cache' => DECADE,

View File

@ -37,9 +37,17 @@ class PageController extends BaseController
public function index(): string
{
$locale = service('request')
->getLocale();
$cacheName = "page-{$this->page->slug}-{$locale}";
$cacheName = implode(
'_',
array_filter([
'page',
$this->page->slug,
service('request')
->getLocale(),
can_user_interact() ? 'authenticated' : null,
]),
);
if (! ($found = cache($cacheName))) {
$data = [
'metatags' => get_page_metatags($this->page),

View File

@ -74,7 +74,7 @@ class PodcastController extends BaseController
'activity',
service('request')
->getLocale(),
can_user_interact() ? '_authenticated' : null,
can_user_interact() ? 'authenticated' : null,
]),
);
@ -122,7 +122,7 @@ class PodcastController extends BaseController
'about',
service('request')
->getLocale(),
can_user_interact() ? '_authenticated' : null,
can_user_interact() ? 'authenticated' : null,
]),
);
@ -188,7 +188,7 @@ class PodcastController extends BaseController
$seasonQuery ? 'season' . $seasonQuery : null,
service('request')
->getLocale(),
can_user_interact() ? '_authenticated' : null,
can_user_interact() ? 'authenticated' : null,
]),
);

View File

@ -81,7 +81,7 @@ class PostController extends FediversePostController
"post#{$this->post->id}",
service('request')
->getLocale(),
can_user_interact() ? '_authenticated' : null,
can_user_interact() ? 'authenticated' : null,
]),
);

View File

@ -307,7 +307,6 @@ if (! function_exists('relative_time')) {
return <<<CODE_SAMPLE
<time-ago class="{$class}" datetime="{$datetime}">
<time
itemprop="published"
datetime="{$datetime}"
title="{$time}">{$translatedDate}</time>
</time-ago>

View File

@ -37,8 +37,8 @@ class Field extends FormComponent
unset($fieldComponentAttributes['as']);
unset($fieldComponentAttributes['label']);
unset($fieldComponentAttributes['class']);
unset($fieldComponentAttributes['helperText']);
unset($fieldComponentAttributes['hintText']);
unset($fieldComponentAttributes['helper']);
unset($fieldComponentAttributes['hint']);
$fieldComponentAttributes['class'] = 'mb-1';

View File

@ -91,7 +91,7 @@
<div class="flex items-center mt-4 gap-x-8">
<?php if ($episode->persons !== []): ?>
<button class="flex items-center text-xs font-semibold gap-x-2 hover:underline focus:ring-accent" data-toggle="persons-list" data-toggle-class="hidden">
<div class="inline-flex flex-row-reverse">
<span class="inline-flex flex-row-reverse">
<?php $i = 0; ?>
<?php foreach ($episode->persons as $person): ?>
<img src="<?= $person->avatar->thumbnail_url ?>" alt="<?= $person->full_name ?>" class="object-cover w-8 h-8 -ml-4 border-2 rounded-full aspect-square border-background-header last:ml-0" loading="lazy" />
@ -99,7 +99,7 @@
break;
}?>
<?php endforeach; ?>
</div>
</span>
<?= lang('Episode.persons', [
'personsCount' => count($episode->persons),
]) ?>
@ -124,7 +124,7 @@
<div class="text-xs">
<?= relative_time($episode->published_at) ?>
<span class="mx-1"></span>
<time datetime="PT<?= $episode->audio->duration ?>S">
<time datetime="PT<?= round($episode->audio->duration, 3) ?>S">
<?= format_duration_symbol($episode->audio->duration) ?>
</time>
</div>

View File

@ -1,6 +1,6 @@
<article class="flex w-full p-4 shadow bg-elevated rounded-conditional-2xl gap-x-2">
<div class="relative">
<time class="absolute px-1 text-xs font-semibold text-white rounded bottom-2 right-2 bg-black/75" datetime="PT<?= $episode->audio->duration ?>S">
<time class="absolute px-1 text-xs font-semibold text-white rounded bottom-2 right-2 bg-black/75" datetime="PT<?= round($episode->audio->duration, 3) ?>S">
<?= format_duration($episode->audio->duration) ?>
</time>
<img src="<?= $episode->cover

View File

@ -1,6 +1,6 @@
<div class="flex items-center border-y border-subtle">
<div class="relative">
<time class="absolute px-1 text-sm font-semibold text-white rounded bg-black/75 bottom-2 right-2" datetime="PT<?= $episode->audio->duration ?>S">
<time class="absolute px-1 text-sm font-semibold text-white rounded bg-black/75 bottom-2 right-2" datetime="PT<?= round($episode->audio->duration, 3) ?>S">
<?= format_duration($episode->audio->duration) ?>
</time>
<img

View File

@ -5,10 +5,6 @@
<head>
<meta charset="UTF-8"/>
<title><?= service('settings')
->get('App.siteName') ?></title>
<meta name="description" content="<?= service('settings')
->get('App.siteDescription') ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="icon" type="image/x-icon" href="<?= service('settings')
->get('App.siteIcon')['ico'] ?>" />
@ -41,20 +37,20 @@
<?php endif; ?>
<header class="py-8 text-white border-b bg-header border-subtle">
<div class="container flex items-center justify-between px-2 py-4 mx-auto">
<h1 class="container flex items-center justify-between px-2 py-4 mx-auto">
<a href="<?= route_to(
'home',
) ?>" class="inline-flex items-baseline text-3xl font-semibold font-display"><?= service('settings')
->get('App.siteName') === 'Castopod' ? 'castopod' .
svg('castopod-logo-base', 'h-6 ml-2') : service('settings')
->get('App.siteName') ?></a>
</div>
</h1>
</header>
<main class="container flex-1 px-4 py-10 mx-auto">
<Heading class="inline-block mb-2"><?= lang('Home.all_podcasts') ?> (<?= count(
<Heading tagName="h2" class="inline-block mb-2"><?= lang('Home.all_podcasts') ?> (<?= count(
$podcasts,
) ?>)</Heading>
<section class="grid gap-4 grid-cols-cards">
<div class="grid gap-4 grid-cols-cards">
<?php if ($podcasts): ?>
<?php foreach ($podcasts as $podcast): ?>
<a href="<?= $podcast->link ?>" class="relative w-full h-full overflow-hidden transition shadow focus:ring-accent rounded-xl border-subtle hover:shadow-xl focus:shadow-xl group border-3">
@ -65,7 +61,7 @@
<img alt="<?= $podcast->title ?>" src="<?= $podcast->cover->medium_url ?>" class="object-cover w-full h-full transition duration-200 ease-in-out transform bg-header aspect-square group-focus:scale-105 group-hover:scale-105" loading="lazy" />
</div>
<div class="absolute bottom-0 left-0 z-20 w-full px-4 pb-2">
<h2 class="font-bold leading-none truncate font-display"><?= $podcast->title ?></h2>
<h3 class="font-bold leading-none truncate font-display"><?= $podcast->title ?></h3>
<p class="text-sm opacity-75">@<?= $podcast->handle ?></p>
</div>
</article>
@ -74,7 +70,7 @@
<?php else: ?>
<p class="italic"><?= lang('Home.no_podcast') ?></p>
<?php endif; ?>
</section>
</div>
</main>
<footer class="container flex justify-between px-2 py-4 mx-auto text-sm text-right border-t border-subtle">
<?= render_page_links() ?>

View File

@ -22,7 +22,7 @@
<div class="flex items-center mt-4 gap-x-8">
<?php if ($podcast->persons !== []): ?>
<button class="flex items-center text-xs font-semibold gap-x-2 hover:underline focus:ring-accent" data-toggle="persons-list" data-toggle-class="hidden">
<div class="inline-flex flex-row-reverse">
<span class="inline-flex flex-row-reverse">
<?php $i = 0; ?>
<?php foreach ($podcast->persons as $person): ?>
<img src="<?= $person->avatar->thumbnail_url ?>" alt="<?= $person->full_name ?>" class="object-cover w-8 -ml-4 border-2 rounded-full aspect-square bg-header border-background-base last:ml-0" loading="lazy" />
@ -30,7 +30,7 @@
break;
}?>
<?php endforeach; ?>
</div>
</span>
<?= lang('Podcast.persons', [
'personsCount' => count($podcast->persons),
]) ?>