Commit ee901bb3 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Plug artist deletion hook & process artists callbacks from the notifier thread

parent 6cfed6e2
......@@ -71,7 +71,9 @@ public:
virtual void onMediaDeleted( std::vector<int64_t> ids ) = 0;
virtual void onArtistAdded( ArtistPtr artist ) = 0;
virtual void onArtistsAdded( std::vector<ArtistPtr> artists ) = 0;
virtual void onArtistsModified( std::vector<ArtistPtr> artist ) = 0;
virtual void onArtistsDeleted( std::vector<int64_t> ids ) = 0;
virtual void onAlbumAdded( AlbumPtr album ) = 0;
/**
......
......@@ -160,6 +160,13 @@ void MediaLibrary::registerEntityHooks()
Media::removeFromCache( rowId );
m_modificationNotifier->notifyMediaRemoval( rowId );
});
m_dbConnection->registerUpdateHook( policy::ArtistTable::Name,
[this]( SqliteConnection::HookReason reason, int64_t rowId ) {
if ( reason != SqliteConnection::HookReason::Delete )
return;
Artist::removeFromCache( rowId );
m_modificationNotifier->notifyArtistRemoval( rowId );
});
}
......
......@@ -29,6 +29,7 @@
#include "Media.h"
#include "Show.h"
#include "utils/Filename.h"
#include "utils/ModificationsNotifier.h"
bool MetadataParser::initialize()
{
......@@ -286,7 +287,7 @@ std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> MetadataParser::hand
LOG_ERROR( "Failed to create new artist ", task.albumArtist );
return {nullptr, nullptr};
}
m_cb->onArtistAdded( albumArtist );
m_notifier->notifyArtistCreation( albumArtist );
}
}
if ( task.artist.empty() == false && task.artist != task.albumArtist )
......@@ -300,7 +301,7 @@ std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> MetadataParser::hand
LOG_ERROR( "Failed to create new artist ", task.artist );
return {nullptr, nullptr};
}
m_cb->onArtistAdded( artist );
m_notifier->notifyArtistCreation( albumArtist );
}
}
return {albumArtist, artist};
......
......@@ -85,6 +85,7 @@ void ParserService::initialize( MediaLibrary* ml, IParserCb* parserCb )
{
m_ml = ml;
m_cb = ml->getCb();
m_notifier = ml->getNotifier();
m_parserCb = parserCb;
// Run the service specific initializer
initialize();
......
......@@ -33,6 +33,7 @@
class IParserCb;
class IMediaLibraryCb;
class ModificationNotifier;
class ParserService
{
......@@ -61,6 +62,7 @@ private:
protected:
MediaLibrary* m_ml;
IMediaLibraryCb* m_cb;
std::shared_ptr<ModificationNotifier> m_notifier;
private:
IParserCb* m_parserCb;
......
......@@ -63,6 +63,21 @@ void ModificationNotifier::notifyMediaRemoval( int64_t mediaId )
notifyRemoval( mediaId, m_media );
}
void ModificationNotifier::notifyArtistCreation( ArtistPtr artist )
{
notifyCreation( std::move( artist ), m_artists );
}
void ModificationNotifier::notifyArtistModification(ArtistPtr artist)
{
notifyModification( std::move( artist ), m_artists );
}
void ModificationNotifier::notifyArtistRemoval( int64_t artist )
{
notifyRemoval( std::move( artist ), m_artists );
}
void ModificationNotifier::run()
{
constexpr auto ZeroTimeout = std::chrono::time_point<std::chrono::steady_clock>{};
......@@ -71,6 +86,7 @@ void ModificationNotifier::run()
// by other threads. That way we can release those early and allow
// more insertions to proceed
Queue<IMedia> media;
Queue<IArtist> artists;
while ( m_stop == false )
{
......@@ -84,12 +100,10 @@ void ModificationNotifier::run()
auto now = std::chrono::steady_clock::now();
auto nextTimeout = ZeroTimeout;
checkQueue( m_media, media, nextTimeout, now );
checkQueue( m_artists, artists, nextTimeout, now );
m_timeout = nextTimeout;
}
notify( std::move( media ), &IMediaLibraryCb::onMediaAdded, &IMediaLibraryCb::onMediaUpdated, &IMediaLibraryCb::onMediaDeleted );
notify( std::move( artists ), &IMediaLibraryCb::onArtistsAdded, &IMediaLibraryCb::onArtistsModified, &IMediaLibraryCb::onArtistsDeleted );
}
}
......@@ -40,10 +40,14 @@ public:
~ModificationNotifier();
void start();
void notifyMediaCreation(MediaPtr media );
void notifyMediaModification(MediaPtr media );
void notifyMediaCreation( MediaPtr media );
void notifyMediaModification( MediaPtr media );
void notifyMediaRemoval( int64_t media );
void notifyArtistCreation( ArtistPtr artist );
void notifyArtistModification( ArtistPtr artist );
void notifyArtistRemoval( int64_t artist );
private:
void run();
void notify();
......@@ -129,6 +133,7 @@ private:
// Queues
Queue<IMedia> m_media;
Queue<IArtist> m_artists;
// Notifier thread
std::mutex m_lock;
......
......@@ -36,7 +36,9 @@ class NoopCallback : public IMediaLibraryCb
virtual void onDiscoveryCompleted(const std::string&) override {}
virtual void onReloadStarted( const std::string& ) override {}
virtual void onReloadCompleted( const std::string& ) override {}
virtual void onArtistAdded( ArtistPtr ) override {}
virtual void onArtistsAdded( std::vector<ArtistPtr> ) override {}
virtual void onArtistsModified( std::vector<ArtistPtr> ) override {}
virtual void onArtistsDeleted( std::vector<int64_t> ) override {}
virtual void onAlbumAdded( AlbumPtr ) override {}
virtual void onTrackAdded( MediaPtr, AlbumTrackPtr ) override {}
virtual void onParsingStatsUpdated( uint32_t ) override {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment