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

Media: Don't store thumbnail generated state in the media table

Use the generated record in the thumbnail table instead
parent c04045e9
......@@ -72,13 +72,12 @@ Media::Media( MediaLibraryPtr ml, sqlite::Row& row )
, m_insertionDate( row.load<decltype(m_insertionDate)>( 7 ) )
, m_releaseDate( row.load<decltype(m_releaseDate)>( 8 ) )
, m_thumbnailId( row.load<decltype(m_thumbnailId)>( 9 ) )
, m_thumbnailGenerated( row.load<decltype(m_thumbnailGenerated)>( 10 ) )
, m_title( row.load<decltype(m_title)>( 11 ) )
, m_filename( row.load<decltype(m_filename)>( 12 ) )
, m_isFavorite( row.load<decltype(m_isFavorite)>( 13 ) )
, m_title( row.load<decltype(m_title)>( 10 ) )
, m_filename( row.load<decltype(m_filename)>( 11 ) )
, m_isFavorite( row.load<decltype(m_isFavorite)>( 12 ) )
// Skip is_present
// Skip device_id
, m_nbPlaylists( row.load<unsigned int>( 16 ) )
, m_nbPlaylists( row.load<unsigned int>( 15 ) )
// Skip folder_id if any field gets added afterward
// End of DB fields extraction
......@@ -98,7 +97,6 @@ Media::Media( MediaLibraryPtr ml, const std::string& title, Type type )
, m_insertionDate( time( nullptr ) )
, m_releaseDate( 0 )
, m_thumbnailId( 0 )
, m_thumbnailGenerated( false )
, m_title( title )
// When creating a Media, meta aren't parsed, and therefor, the title is the filename
, m_filename( title )
......@@ -309,7 +307,7 @@ Query<ISubtitleTrack> Media::subtitleTracks() const
const std::string& Media::thumbnail() const
{
if ( m_thumbnailId == 0 || m_thumbnailGenerated == false )
if ( isThumbnailGenerated() == false )
return Thumbnail::EmptyMrl;
if ( m_thumbnail == nullptr )
......@@ -326,7 +324,7 @@ const std::string& Media::thumbnail() const
bool Media::isThumbnailGenerated() const
{
return m_thumbnailGenerated;
return m_thumbnailId != 0;
}
unsigned int Media::insertionDate() const
......@@ -413,11 +411,10 @@ bool Media::setThumbnail( const std::string& thumbnailMrl, Thumbnail::Origin ori
return false;
static const std::string req = "UPDATE " + Media::Table::Name + " SET "
"thumbnail_id = ?, thumbnail_generated = 1 WHERE id_media = ?";
"thumbnail_id = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, thumbnail->id(), m_id ) == false )
return false;
m_thumbnailId = thumbnail->id();
m_thumbnailGenerated = true;
m_thumbnail = std::move( thumbnail );
if ( t != nullptr )
t->commit();
......
......@@ -178,7 +178,6 @@ private:
const std::time_t m_insertionDate;
unsigned int m_releaseDate;
int64_t m_thumbnailId;
unsigned int m_thumbnailGenerated;
std::string m_title;
// We store the filename as a shortcut when sorting. The filename (*not* the title
// might be used as a fallback
......
......@@ -28,7 +28,7 @@
"INSERT INTO " + Media::Table::Name + "("
"id_media, type, subtype, duration, play_count, last_played_date, real_last_played_date, insertion_date,"
"release_date, thumbnail_id, thumbnail_generated, title, filename, is_favorite,"
"release_date, thumbnail_id, title, filename, is_favorite,"
"is_present) "
"SELECT id_media, type, ifnull(subtype, " +
std::to_string( static_cast<typename std::underlying_type<IMedia::SubType>::type>(
......@@ -37,7 +37,6 @@
"strftime('%s', 'now'),"
"insertion_date, release_date, "
"CASE thumbnail WHEN NULL THEN 0 WHEN '' THEN 0 ELSE id_media END,"
"CASE thumbnail WHEN NULL THEN 0 WHEN '' THEN 0 ELSE 1 END,"
"title, filename, is_favorite, is_present FROM " + Media::Table::Name + "_backup",
"DROP TABLE " + Media::Table::Name + "_backup",
......
......@@ -11,7 +11,6 @@
"insertion_date UNSIGNED INTEGER,"
"release_date UNSIGNED INTEGER,"
"thumbnail_id INTEGER,"
"thumbnail_generated BOOLEAN NOT NULL DEFAULT 0,"
"title TEXT COLLATE NOCASE,"
"filename TEXT COLLATE NOCASE,"
"is_favorite BOOLEAN NOT NULL DEFAULT 0,"
......
......@@ -103,3 +103,18 @@ TEST_F( Thumbnails, GeneratedPath )
t = Thumbnail::fetch( ml.get(), t->id() );
ASSERT_EQ( expectedMrl, t->mrl() );
}
TEST_F( Thumbnails, MarkFailure )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv" ) );
ASSERT_FALSE( m->isThumbnailGenerated() );
auto res = m->setThumbnail( "", Thumbnail::Origin::Media, true );
ASSERT_TRUE( res );
ASSERT_TRUE( m->isThumbnailGenerated() );
Reload();
m = std::static_pointer_cast<Media>( ml->media( m->id() ) );
ASSERT_TRUE( m->isThumbnailGenerated() );
}
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