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

Database: Ensure all removed entities are removed from cache

parent 7d962ef1
......@@ -160,6 +160,14 @@ bool MediaLibrary::createAllTables()
return true;
}
template <typename T>
static void propagateDeletionToCache( SqliteConnection::HookReason reason, int64_t rowId )
{
if ( reason != SqliteConnection::HookReason::Delete )
return;
T::removeFromCache( rowId );
}
void MediaLibrary::registerEntityHooks()
{
if ( m_modificationNotifier == nullptr )
......@@ -200,6 +208,16 @@ void MediaLibrary::registerEntityHooks()
Playlist::removeFromCache( rowId );
m_modificationNotifier->notifyPlaylistRemoval( rowId );
});
m_dbConnection->registerUpdateHook( policy::DeviceTable::Name, &propagateDeletionToCache<Device> );
m_dbConnection->registerUpdateHook( policy::FileTable::Name, &propagateDeletionToCache<File> );
m_dbConnection->registerUpdateHook( policy::FolderTable::Name, &propagateDeletionToCache<Folder> );
m_dbConnection->registerUpdateHook( policy::GenreTable::Name, &propagateDeletionToCache<Genre> );
m_dbConnection->registerUpdateHook( policy::LabelTable::Name, &propagateDeletionToCache<Label> );
m_dbConnection->registerUpdateHook( policy::MovieTable::Name, &propagateDeletionToCache<Movie> );
m_dbConnection->registerUpdateHook( policy::ShowTable::Name, &propagateDeletionToCache<Show> );
m_dbConnection->registerUpdateHook( policy::ShowEpisodeTable::Name, &propagateDeletionToCache<ShowEpisode> );
m_dbConnection->registerUpdateHook( policy::AudioTrackTable::Name, &propagateDeletionToCache<AudioTrack> );
m_dbConnection->registerUpdateHook( policy::VideoTrackTable::Name, &propagateDeletionToCache<VideoTrack> );
}
......
......@@ -161,12 +161,12 @@ class DatabaseHelpers
{
static const std::string req = "DELETE FROM " + TABLEPOLICY::Name + " WHERE "
+ TABLEPOLICY::PrimaryKeyColumn + " = ?";
auto res = sqlite::Tools::executeDelete( ml->getConn(), req, pkValue );
if ( res == true )
CACHEPOLICY::remove( pkValue );
return res;
return sqlite::Tools::executeDelete( ml->getConn(), req, pkValue );
}
/**
* @warning removeFromCache is only meant to be called from an SQLite hook
*/
static void removeFromCache( int64_t pkValue )
{
CACHEPOLICY::remove( pkValue );
......
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