finder = $finder;
$this->articlesCache = $articlesCache;
$this->params = $params;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$env = $this->params->get('kernel.environment');
$cacheKey = 'latest_articles_list_' . $env;
$cacheItem = $this->articlesCache->getItem($cacheKey);
$key = new Key();
$excludedPubkeys = [
$key->convertToHex('npub1etsrcjz24fqewg4zmjze7t5q8c6rcwde5zdtdt4v3t3dz2navecscjjz94'), // Bitcoin Magazine (News Bot)
$key->convertToHex('npub1m7szwpud3jh2k3cqe73v0fd769uzsj6rzmddh4dw67y92sw22r3sk5m3ys'), // No Bullshit Bitcoin (News Bot)
$key->convertToHex('npub13wke9s6njrmugzpg6mqtvy2d49g4d6t390ng76dhxxgs9jn3f2jsmq82pk'), // TFTC (News Bot)
$key->convertToHex('npub10akm29ejpdns52ca082skmc3hr75wmv3ajv4987c9lgyrfynrmdqduqwlx'), // Discreet Log (News Bot)
$key->convertToHex('npub13uvnw9qehqkds68ds76c4nfcn3y99c2rl9z8tr0p34v7ntzsmmzspwhh99'), // Batcoinz (Just annoying)
$key->convertToHex('npub1fls5au5fxj6qj0t36sage857cs4tgfpla0ll8prshlhstagejtkqc9s2yl'), // AGORA Marketplace - feed 𝚋𝚘𝚝 (Just annoying)
];
if (!$cacheItem->isHit()) {
$boolQuery = new BoolQuery();
$boolQuery->addMustNot(new Terms('pubkey', $excludedPubkeys));
$query = new Query($boolQuery);
$query->setSize(50);
$query->setSort(['createdAt' => ['order' => 'desc']]);
$collapse = new Collapse();
$collapse->setFieldname('slug');
$query->setCollapse($collapse);
$articles = $this->finder->find($query);
$cacheItem->set($articles);
$cacheItem->expiresAfter(3600); // Cache for 1 hour
$this->articlesCache->save($cacheItem);
$output->writeln('Cached ' . count($articles) . ' articles.');
} else {
$output->writeln('Cache already exists for key: ' . $cacheKey . '');
}
return Command::SUCCESS;
}
}