From 418a70b2a670d8ba0ab6c15fa5faa41f6be55e53 Mon Sep 17 00:00:00 2001 From: Yassine Doghri <yassine@doghri.fr> Date: Sun, 23 Jan 2022 19:00:08 +0000 Subject: [PATCH] fix(cache): suffix cache names with authenticated for credits, map and pages --- app/Controllers/CreditsController.php | 8 ++++++-- app/Controllers/EpisodeCommentController.php | 2 +- app/Controllers/MapController.php | 14 +++++++++++--- app/Controllers/PageController.php | 14 +++++++++++--- app/Controllers/PodcastController.php | 6 +++--- app/Controllers/PostController.php | 2 +- app/Helpers/components_helper.php | 1 - app/Views/Components/Forms/Field.php | 4 ++-- themes/cp_app/episode/_layout.php | 6 +++--- themes/cp_app/episode/_partials/card.php | 2 +- themes/cp_app/episode/_partials/preview_card.php | 2 +- themes/cp_app/home.php | 16 ++++++---------- themes/cp_app/podcast/about.php | 4 ++-- 13 files changed, 48 insertions(+), 33 deletions(-) diff --git a/app/Controllers/CreditsController.php b/app/Controllers/CreditsController.php index 3531b3e2e8..5d20669ea3 100644 --- a/app/Controllers/CreditsController.php +++ b/app/Controllers/CreditsController.php @@ -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: diff --git a/app/Controllers/EpisodeCommentController.php b/app/Controllers/EpisodeCommentController.php index 61fb6bac69..e0753ce912 100644 --- a/app/Controllers/EpisodeCommentController.php +++ b/app/Controllers/EpisodeCommentController.php @@ -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, ]), ); diff --git a/app/Controllers/MapController.php b/app/Controllers/MapController.php index 785a1352ae..4e46838971 100644 --- a/app/Controllers/MapController.php +++ b/app/Controllers/MapController.php @@ -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, diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index a97e416389..0377392113 100644 --- a/app/Controllers/PageController.php +++ b/app/Controllers/PageController.php @@ -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), diff --git a/app/Controllers/PodcastController.php b/app/Controllers/PodcastController.php index 71c5c283b1..75b78def4d 100644 --- a/app/Controllers/PodcastController.php +++ b/app/Controllers/PodcastController.php @@ -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, ]), ); diff --git a/app/Controllers/PostController.php b/app/Controllers/PostController.php index 430a1ca061..15b23c162a 100644 --- a/app/Controllers/PostController.php +++ b/app/Controllers/PostController.php @@ -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, ]), ); diff --git a/app/Helpers/components_helper.php b/app/Helpers/components_helper.php index 7c7073f4b0..4502c0f201 100644 --- a/app/Helpers/components_helper.php +++ b/app/Helpers/components_helper.php @@ -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> diff --git a/app/Views/Components/Forms/Field.php b/app/Views/Components/Forms/Field.php index 8f81fc242f..8467df6434 100644 --- a/app/Views/Components/Forms/Field.php +++ b/app/Views/Components/Forms/Field.php @@ -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'; diff --git a/themes/cp_app/episode/_layout.php b/themes/cp_app/episode/_layout.php index 8fb8aeca96..1914950667 100644 --- a/themes/cp_app/episode/_layout.php +++ b/themes/cp_app/episode/_layout.php @@ -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> diff --git a/themes/cp_app/episode/_partials/card.php b/themes/cp_app/episode/_partials/card.php index 22de5e04c2..9b53fdb1d4 100644 --- a/themes/cp_app/episode/_partials/card.php +++ b/themes/cp_app/episode/_partials/card.php @@ -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 diff --git a/themes/cp_app/episode/_partials/preview_card.php b/themes/cp_app/episode/_partials/preview_card.php index 4554051227..0507fc1513 100644 --- a/themes/cp_app/episode/_partials/preview_card.php +++ b/themes/cp_app/episode/_partials/preview_card.php @@ -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 diff --git a/themes/cp_app/home.php b/themes/cp_app/home.php index b217e82faf..39abc5cdc6 100644 --- a/themes/cp_app/home.php +++ b/themes/cp_app/home.php @@ -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() ?> diff --git a/themes/cp_app/podcast/about.php b/themes/cp_app/podcast/about.php index 24b6a674a0..2a1178c9ad 100644 --- a/themes/cp_app/podcast/about.php +++ b/themes/cp_app/podcast/about.php @@ -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), ]) ?> -- GitLab