Commit 9289272c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Settings: Add a column to store the number of cached media

parent 2a8ba608
......@@ -2099,6 +2099,9 @@ void MediaLibrary::migrateModel36to37()
for ( const auto& req : reqs )
sqlite::Tools::executeRequest( dbConn, req );
Settings::createTable( dbConn );
m_settings.load();
m_settings.setDbModelVersion( 37 );
t->commit();
}
......
......@@ -35,6 +35,7 @@ namespace medialibrary
const uint32_t Settings::DbModelVersion = 37u;
const uint32_t Settings::MaxTaskAttempts = 2u;
const uint32_t Settings::MaxLinkTaskAttempts = 6u;
const uint32_t Settings::DefaultNbCachedMediaPerCollection = 2u;
Settings::Settings( MediaLibrary* ml )
: m_ml( ml )
......@@ -50,8 +51,9 @@ bool Settings::load()
if ( row == nullptr )
{
if ( sqlite::Tools::executeInsert( m_ml->getConn(),
"INSERT INTO Settings VALUES(?, ?, ?)",
DbModelVersion, MaxTaskAttempts, MaxLinkTaskAttempts ) == false )
"INSERT INTO Settings VALUES(?, ?, ?, ?)",
DbModelVersion, MaxTaskAttempts, MaxLinkTaskAttempts,
DefaultNbCachedMediaPerCollection ) == false )
{
return false;
}
......@@ -60,6 +62,8 @@ bool Settings::load()
else
{
row >> m_dbModelVersion;
if ( m_dbModelVersion >= 37 )
row >> m_nbCachedMediaPerCollection;
// safety check: there sould only be one row
assert( s.row() == nullptr );
}
......@@ -81,12 +85,24 @@ bool Settings::setDbModelVersion( uint32_t dbModelVersion )
return true;
}
bool Settings::setNbCachedMediaPerCollection( uint32_t nbCachedMedia )
{
if ( m_nbCachedMediaPerCollection == nbCachedMedia )
return true;
const std::string req = "UPDATE Settings SET nb_cached_media_per_collection = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, nbCachedMedia ) == false )
return false;
m_nbCachedMediaPerCollection = nbCachedMedia;
return true;
}
void Settings::createTable( sqlite::Connection* dbConn )
{
const std::string req = "CREATE TABLE IF NOT EXISTS Settings("
"db_model_version UNSIGNED INTEGER NOT NULL,"
"max_task_attempts UNSIGNED INTEGER NOT NULL,"
"max_link_task_attempts UNSIGNED INTEGER NOT NULL"
"max_link_task_attempts UNSIGNED INTEGER NOT NULL,"
"nb_cached_media_per_collection UNSIGNED INTEGER NOT NULL"
")";
sqlite::Tools::executeRequest( dbConn, req );
}
......
......@@ -47,17 +47,20 @@ public:
*/
uint32_t dbModelVersion() const;
bool setDbModelVersion( uint32_t dbModelVersion );
bool setNbCachedMediaPerCollection( uint32_t nbCachedMedia );
static void createTable( sqlite::Connection* dbConn );
static const uint32_t DbModelVersion;
static const uint32_t MaxTaskAttempts;
static const uint32_t MaxLinkTaskAttempts;
static const uint32_t DefaultNbCachedMediaPerCollection;
private:
MediaLibrary* m_ml;
uint32_t m_dbModelVersion;
uint32_t m_nbCachedMediaPerCollection;
};
}
......
......@@ -192,3 +192,6 @@ Collection::trigger( Collection::Triggers::PropagateTaskDeletion, 37 ),
Collection::trigger( Collection::Triggers::IncrementCachedSize, 37 ),
Collection::trigger( Collection::Triggers::DecrementCachedSize, 37 ),
Collection::trigger( Collection::Triggers::DecrementCachedSizeOnRemoval, 37 ),
"DROP TABLE Settings",
Supports Markdown
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