From fb27968af1da99d533594950764f7fe3d915af76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Wed, 8 Oct 2025 12:08:03 +0200 Subject: [PATCH] Media, optimization --- src/Command/CacheMediaDiscoveryCommand.php | 12 +++++++----- src/Controller/MediaDiscoveryController.php | 5 ++--- src/Service/NostrClient.php | 1 + templates/pages/media-discovery.html.twig | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Command/CacheMediaDiscoveryCommand.php b/src/Command/CacheMediaDiscoveryCommand.php index 9a1d5ed..50ad6f4 100644 --- a/src/Command/CacheMediaDiscoveryCommand.php +++ b/src/Command/CacheMediaDiscoveryCommand.php @@ -21,12 +21,13 @@ use Symfony\Contracts\Cache\CacheInterface; )] class CacheMediaDiscoveryCommand extends Command { - private const int CACHE_TTL = 10800; // 3 hours in seconds + private const int CACHE_TTL = 32500; // 9ish hours in seconds // Hardcoded topic to hashtag mapping (same as controller) private const TOPIC_HASHTAGS = [ - 'photography' => ['photography', 'photo', 'photostr', 'photographer', 'photos', 'picture'], - 'nature' => ['nature', 'landscape', 'wildlife', 'outdoor', 'naturephotography', 'pets', 'catstr', 'dogstr', 'flowers', 'forest', 'mountains', 'beach', 'sunset', 'sunrise'], + 'photography' => ['photography', 'photo', 'photostr', 'photographer', 'photos', 'picture', 'image', 'images', 'gallery', 'coffee'], + 'nature' => ['nature', 'landscape', 'wildlife', 'outdoor', 'naturephotography', 'pets', 'catstr', 'dogstr', + 'flowers', 'forest', 'mountains', 'beach', 'sunset', 'sunrise'], 'travel' => ['travel', 'traveling', 'wanderlust', 'adventure', 'explore', 'city', 'vacation', 'trip'], ]; @@ -48,7 +49,8 @@ class CacheMediaDiscoveryCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $force = $input->getOption('force'); + $force = true; // Always force refresh for this command + // $force = $input->getOption('force'); $io->title('Media Discovery Cache Update'); @@ -59,7 +61,7 @@ class CacheMediaDiscoveryCommand extends Command $allHashtags = array_merge($allHashtags, self::TOPIC_HASHTAGS[$topic]); } - $cacheKey = 'media_discovery_events_' . md5(implode(',', $allHashtags)); + $cacheKey = 'media_discovery_events_all'; if ($force) { $io->info('Force refresh enabled - deleting existing cache'); diff --git a/src/Controller/MediaDiscoveryController.php b/src/Controller/MediaDiscoveryController.php index cdf6497..8208cdc 100644 --- a/src/Controller/MediaDiscoveryController.php +++ b/src/Controller/MediaDiscoveryController.php @@ -34,11 +34,10 @@ class MediaDiscoveryController extends AbstractController } // Cache key for all media events - $cacheKey = 'media_discovery_events_' . md5(implode(',', $allHashtags)); + $cacheKey = 'media_discovery_events_all'; // Read from cache only - the cache is populated by the CacheMediaDiscoveryCommand - $allCachedEvents = $cache->get($cacheKey, function (ItemInterface $item) { - $item->expiresAfter(self::CACHE_TTL); + $allCachedEvents = $cache->get($cacheKey, function () { // Return empty array if cache is not populated yet // The command should be run to populate this return []; diff --git a/src/Service/NostrClient.php b/src/Service/NostrClient.php index bd9bab2..d51e9f1 100644 --- a/src/Service/NostrClient.php +++ b/src/Service/NostrClient.php @@ -668,6 +668,7 @@ class NostrClient $allEvents = []; $relayset = new RelaySet(); $relayset->addRelay(new Relay('wss://theforest.nostr1.com')); + $relayset->addRelay(new Relay('wss://relay.nostr.band')); // Fetch events for each hashtag foreach ($hashtags as $hashtag) { diff --git a/templates/pages/media-discovery.html.twig b/templates/pages/media-discovery.html.twig index 4125125..f1a003f 100644 --- a/templates/pages/media-discovery.html.twig +++ b/templates/pages/media-discovery.html.twig @@ -8,7 +8,7 @@ {% block body %}
-

Media

+

Multimedia

Discovery through serendipity

@@ -155,7 +155,7 @@ {% else %}