Browse Source

Media, optimization

imwald
Nuša Pukšič 3 months ago
parent
commit
fb27968af1
  1. 12
      src/Command/CacheMediaDiscoveryCommand.php
  2. 5
      src/Controller/MediaDiscoveryController.php
  3. 1
      src/Service/NostrClient.php
  4. 4
      templates/pages/media-discovery.html.twig

12
src/Command/CacheMediaDiscoveryCommand.php

@ -21,12 +21,13 @@ use Symfony\Contracts\Cache\CacheInterface;
)] )]
class CacheMediaDiscoveryCommand extends Command 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) // Hardcoded topic to hashtag mapping (same as controller)
private const TOPIC_HASHTAGS = [ private const TOPIC_HASHTAGS = [
'photography' => ['photography', 'photo', 'photostr', 'photographer', 'photos', 'picture'], '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'], 'nature' => ['nature', 'landscape', 'wildlife', 'outdoor', 'naturephotography', 'pets', 'catstr', 'dogstr',
'flowers', 'forest', 'mountains', 'beach', 'sunset', 'sunrise'],
'travel' => ['travel', 'traveling', 'wanderlust', 'adventure', 'explore', 'city', 'vacation', 'trip'], '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 protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$io = new SymfonyStyle($input, $output); $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'); $io->title('Media Discovery Cache Update');
@ -59,7 +61,7 @@ class CacheMediaDiscoveryCommand extends Command
$allHashtags = array_merge($allHashtags, self::TOPIC_HASHTAGS[$topic]); $allHashtags = array_merge($allHashtags, self::TOPIC_HASHTAGS[$topic]);
} }
$cacheKey = 'media_discovery_events_' . md5(implode(',', $allHashtags)); $cacheKey = 'media_discovery_events_all';
if ($force) { if ($force) {
$io->info('Force refresh enabled - deleting existing cache'); $io->info('Force refresh enabled - deleting existing cache');

5
src/Controller/MediaDiscoveryController.php

@ -34,11 +34,10 @@ class MediaDiscoveryController extends AbstractController
} }
// Cache key for all media events // 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 // Read from cache only - the cache is populated by the CacheMediaDiscoveryCommand
$allCachedEvents = $cache->get($cacheKey, function (ItemInterface $item) { $allCachedEvents = $cache->get($cacheKey, function () {
$item->expiresAfter(self::CACHE_TTL);
// Return empty array if cache is not populated yet // Return empty array if cache is not populated yet
// The command should be run to populate this // The command should be run to populate this
return []; return [];

1
src/Service/NostrClient.php

@ -668,6 +668,7 @@ class NostrClient
$allEvents = []; $allEvents = [];
$relayset = new RelaySet(); $relayset = new RelaySet();
$relayset->addRelay(new Relay('wss://theforest.nostr1.com')); $relayset->addRelay(new Relay('wss://theforest.nostr1.com'));
$relayset->addRelay(new Relay('wss://relay.nostr.band'));
// Fetch events for each hashtag // Fetch events for each hashtag
foreach ($hashtags as $hashtag) { foreach ($hashtags as $hashtag) {

4
templates/pages/media-discovery.html.twig

@ -8,7 +8,7 @@
{% block body %} {% block body %}
<div class="discover-header"> <div class="discover-header">
<h1>Media</h1> <h1>Multimedia</h1>
<p class="discover-subtitle">Discovery through serendipity</p> <p class="discover-subtitle">Discovery through serendipity</p>
</div> </div>
@ -155,7 +155,7 @@
</div> </div>
<div class="discover-footer"> <div class="discover-footer">
<p class="media-count">End of the line. Reload for a new batch.</p> <p class="media-count">End of the line. Refresh to load a new batch.</p>
</div> </div>
{% else %} {% else %}
<div class="no-media"> <div class="no-media">

Loading…
Cancel
Save