Update search formatting, master key, "enable" flag.

This commit is contained in:
Buster Neece 2023-02-22 11:13:34 -06:00
parent 8d6fb4b81c
commit 01892a9c14
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
11 changed files with 74 additions and 31 deletions

View File

@ -136,7 +136,8 @@ ENV TZ="UTC" \
PROFILING_EXTENSION_HTTP_KEY=dev \
PROFILING_EXTENSION_HTTP_IP_WHITELIST=* \
ENABLE_WEB_UPDATER="true" \
MEILI_MASTER_KEY="zejNISMlGe_6IUGBsdjfG6c6Qi8g2RngTxOmWsTbwvw"
ENABLE_MEILISEARCH="true" \
MEILISEARCH_MASTER_KEY="zejNISMlGe_6IUGBsdjfG6c6Qi8g2RngTxOmWsTbwvw"
# Entrypoint and default command
ENTRYPOINT ["tini", "--", "/usr/local/bin/my_init"]

View File

@ -185,7 +185,7 @@
class="btn-search"
href="#"
:title="$gettext('View tracks in playlist')"
@click.prevent="filter('playlist:'+playlist.name)"
@click.prevent="filter('playlist:'+playlist.short_name)"
>{{ playlist.name }}</a>
<span v-if="index+1 < row.item.playlists.length">, </span>
</template>

View File

@ -216,9 +216,12 @@ final class ListAction
if (isset($playlists[$playlistId])) {
$playlists[$playlistId]['count']++;
} else {
$playlistName = $spmRow['playlist']['name'];
$playlists[$playlistId] = [
'id' => $playlistId,
'name' => $spmRow['playlist']['name'],
'name' => $playlistName,
'short_name' => Entity\StationPlaylist::generateShortName($playlistName),
'count' => 1,
];
}
@ -241,6 +244,9 @@ final class ListAction
$foldersInDir[$folderRow['path']]['playlists'][] = [
'id' => $folderRow['playlist']['id'],
'name' => $folderRow['playlist']['name'],
'short_name' => Entity\StationPlaylist::generateShortName(
$folderRow['playlist']['name']
),
];
}
@ -366,11 +372,32 @@ final class ListAction
preg_match('/playlist:(\w*)/', $query, $matches, PREG_UNMATCHED_AS_NULL);
if ($matches[1]) {
$playlistId = $matches[1];
if (!is_numeric($playlistId)) {
$playlistNameLookupRaw = $this->em->createQuery(
<<<'DQL'
SELECT sp.id, sp.name
FROM App\Entity\StationPlaylist sp
WHERE sp.station = :station
DQL
)->setParameter('station', $station)
->getArrayResult();
foreach ($playlistNameLookupRaw as $playlistRow) {
$shortName = Entity\StationPlaylist::generateShortName($playlistRow['name']);
if ($shortName === $playlistId) {
$playlistId = $playlistRow['id'];
break;
}
}
}
$playlist = $this->em->getRepository(Entity\StationPlaylist::class)
->findOneBy(
[
'station' => $station,
'name' => $matches[1],
'id' => $playlistId,
]
);
}

View File

@ -267,6 +267,8 @@ final class PlaylistsController extends AbstractScheduledEntityController
)->setParameter('playlist', $record)
->getArrayResult();
$return['short_name'] = Entity\StationPlaylist::generateShortName($return['name']);
$return['num_songs'] = (int)$song_totals[0]['num_songs'];
$return['total_length'] = (int)$song_totals[0]['total_length'];

View File

@ -54,7 +54,8 @@ final class Environment
public const ENABLE_WEB_UPDATER = 'ENABLE_WEB_UPDATER';
public const MEILI_MASTER_KEY = 'MEILI_MASTER_KEY';
public const ENABLE_MEILISEARCH = 'ENABLE_MEILISEARCH';
public const MEILISEARCH_MASTER_KEY = 'MEILISEARCH_MASTER_KEY';
// Database and Cache Configuration Variables
public const DB_HOST = 'MYSQL_HOST';
@ -93,7 +94,8 @@ final class Environment
self::ENABLE_WEB_UPDATER => false,
self::MEILI_MASTER_KEY => 'azur4c457',
self::ENABLE_MEILISEARCH => false,
self::MEILISEARCH_MASTER_KEY => '',
];
public function __construct(array $elements = [])
@ -374,9 +376,15 @@ final class Environment
return $this->isDocker() && self::envToBool($this->data[self::ENABLE_WEB_UPDATER] ?? false);
}
public function getMeiliMasterKey(): string
public function enableMeilisearch(): bool
{
return $this->data[self::MEILI_MASTER_KEY] ?? $this->defaults[self::MEILI_MASTER_KEY];
return $this->isDocker() && !$this->isTesting() &&
self::envToBool($this->data[self::ENABLE_MEILISEARCH] ?? false);
}
public function getMeilisearchMasterKey(): string
{
return $this->data[self::MEILISEARCH_MASTER_KEY] ?? $this->defaults[self::MEILISEARCH_MASTER_KEY];
}
public static function getDefaultsForEnvironment(Environment $existingEnv): self

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Message\Meilisearch;
use App\Message\AbstractMessage;
use App\MessageQueue\QueueNames;
final class AddMediaMessage extends AbstractMessage
{
@ -16,4 +17,9 @@ final class AddMediaMessage extends AbstractMessage
/** @var bool Whether to include playlist data. */
public bool $include_playlists = false;
public function getQueue(): QueueNames
{
return QueueNames::SearchIndex;
}
}

View File

@ -9,6 +9,7 @@ enum QueueNames: string
case HighPriority = 'high_priority';
case NormalPriority = 'normal_priority';
case LowPriority = 'low_priority';
case SearchIndex = 'search_index';
case Media = 'media';
case PodcastMedia = 'podcast_media';
}

View File

@ -25,7 +25,7 @@ final class Meilisearch
public function isSupported(): bool
{
return $this->environment->isDocker() && !$this->environment->isTesting();
return $this->environment->enableMeilisearch();
}
public function getClient(): Client
@ -40,7 +40,7 @@ final class Meilisearch
$psrFactory = new HttpFactory();
$client = new Client(
'http://localhost:6070',
$this->environment->getMeiliMasterKey(),
$this->environment->getMeilisearchMasterKey(),
$this->httpClient,
requestFactory: $psrFactory,
streamFactory: $psrFactory

View File

@ -8,6 +8,7 @@ use App\Doctrine\ReloadableEntityManagerInterface;
use App\Entity;
use App\Message\Meilisearch\AddMediaMessage;
use App\MessageQueue\QueueManagerInterface;
use App\MessageQueue\QueueNames;
use App\Service\Meilisearch;
use Doctrine\ORM\AbstractQuery;
use Psr\Log\LoggerInterface;
@ -42,6 +43,8 @@ final class UpdateMeilisearchIndex extends AbstractTask
return;
}
$this->queueManager->clearQueue(QueueNames::SearchIndex);
$storageLocations = $this->iterateStorageLocations(Entity\Enums\StorageLocationTypes::StationMedia);
foreach ($storageLocations as $storageLocation) {
@ -72,21 +75,6 @@ final class UpdateMeilisearchIndex extends AbstractTask
$existingIds = $index->getIdsInIndex();
$stats['existing'] = count($existingIds);
$queuedMedia = [];
foreach (
$this->queueManager->getMessagesInTransport(
QueueManagerInterface::QUEUE_NORMAL_PRIORITY
) as $message
) {
if ($message instanceof AddMediaMessage) {
foreach ($message->media_ids as $mediaId) {
$queuedMedia[$mediaId] = $mediaId;
$stats['queued']++;
}
}
}
$mediaRaw = $this->em->createQuery(
<<<'DQL'
SELECT sm.id, sm.mtime
@ -102,11 +90,6 @@ final class UpdateMeilisearchIndex extends AbstractTask
foreach ($mediaRaw as $row) {
$mediaId = $row['id'];
if (isset($queuedMedia[$mediaId])) {
unset($existingIds[$mediaId]);
continue;
}
if (isset($existingIds[$mediaId])) {
if ($existingIds[$mediaId] < $row['mtime']) {
$idsToUpdate[] = $mediaId;

View File

@ -1,5 +1,5 @@
[program:meilisearch]
command=meilisearch --config-file-path=/var/azuracast/meilisearch/config.toml
command=meilisearch --config-file-path=/var/azuracast/meilisearch/config.toml --master-key %(ENV_MEILISEARCH_MASTER_KEY)s
priority=500
numprocs=1
autostart=true

View File

@ -0,0 +1,15 @@
#!/bin/bash
bool() {
case "$1" in
Y* | y* | true | TRUE | 1) return 0 ;;
esac
return 1
}
ENABLE_MEILISEARCH=${ENABLE_MEILISEARCH:-true}
if ! bool "$ENABLE_MEILISEARCH"; then
echo "Meilisearch is disabled..."
rm -rf /etc/supervisor/full.conf.d/meilisearch.conf
fi