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

Media: Index last playback & insertion dates

parent f0242c72
...@@ -587,13 +587,21 @@ void Media::setFileName( std::string fileName ) ...@@ -587,13 +587,21 @@ void Media::setFileName( std::string fileName )
m_filename = std::move( fileName ); m_filename = std::move( fileName );
} }
void Media::createTable( sqlite::Connection* connection ) void Media::createTable( sqlite::Connection* connection, uint32_t modelVersion )
{ {
std::string reqs[] = { std::string reqs[] = {
#include "database/tables/Media_v14.sql" #include "database/tables/Media_v14.sql"
}; };
for ( const auto& req : reqs ) for ( const auto& req : reqs )
sqlite::Tools::executeRequest( connection, req ); sqlite::Tools::executeRequest( connection, req );
if ( modelVersion >= 14 )
{
// Don't create this index before model 14, as the real_last_played_date
// was introduced in model version 14
const auto req = "CREATE INDEX IF NOT EXISTS media_last_usage_dates_idx ON " + Media::Table::Name +
"(last_played_date, real_last_played_date, insertion_date)";
sqlite::Tools::executeRequest( connection, req );
}
} }
void Media::createTriggers( sqlite::Connection* connection, uint32_t modelVersion ) void Media::createTriggers( sqlite::Connection* connection, uint32_t modelVersion )
......
...@@ -62,7 +62,7 @@ class Media : public IMedia, public DatabaseHelpers<Media> ...@@ -62,7 +62,7 @@ class Media : public IMedia, public DatabaseHelpers<Media>
Media( MediaLibraryPtr ml, const std::string& title, Type type); Media( MediaLibraryPtr ml, const std::string& title, Type type);
static std::shared_ptr<Media> create( MediaLibraryPtr ml, Type type, const std::string& fileName ); static std::shared_ptr<Media> create( MediaLibraryPtr ml, Type type, const std::string& fileName );
static void createTable( sqlite::Connection* connection ); static void createTable( sqlite::Connection* connection, uint32_t modelVersion );
static void createTriggers( sqlite::Connection* connection, uint32_t modelVersion ); static void createTriggers( sqlite::Connection* connection, uint32_t modelVersion );
virtual int64_t id() const override; virtual int64_t id() const override;
......
...@@ -153,7 +153,7 @@ void MediaLibrary::createAllTables() ...@@ -153,7 +153,7 @@ void MediaLibrary::createAllTables()
Device::createTable( m_dbConnection.get() ); Device::createTable( m_dbConnection.get() );
Folder::createTable( m_dbConnection.get() ); Folder::createTable( m_dbConnection.get() );
Thumbnail::createTable( m_dbConnection.get() ); Thumbnail::createTable( m_dbConnection.get() );
Media::createTable( m_dbConnection.get() ); Media::createTable( m_dbConnection.get(), dbModelVersion );
File::createTable( m_dbConnection.get() ); File::createTable( m_dbConnection.get() );
Label::createTable( m_dbConnection.get() ); Label::createTable( m_dbConnection.get() );
Playlist::createTable( m_dbConnection.get(), dbModelVersion ); Playlist::createTable( m_dbConnection.get(), dbModelVersion );
......
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