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

Thumbnail: Add a helper to set the mrl with its primary key.

This will be used by all classes using the Thumbnail class
parent 341d4de4
......@@ -370,19 +370,9 @@ void Media::setReleaseDate( unsigned int date )
bool Media::setThumbnail( const std::string& thumbnailMrl, Thumbnail::Origin origin )
{
if ( m_thumbnailId != 0 )
{
auto lock = m_thumbnail.lock();
if ( m_thumbnail.isCached() == false )
{
m_thumbnail = Thumbnail::fetch( m_ml, m_thumbnailId );
if ( m_thumbnail.get() == nullptr )
{
LOG_WARN( "Failed to fetch thumbnail entity #", m_thumbnailId );
return false;
}
}
return m_thumbnail.get()->setMrl( thumbnailMrl );
}
return Thumbnail::setMrlFromPrimaryKey( m_ml, m_thumbnail, m_thumbnailId,
thumbnailMrl );
std::unique_ptr<sqlite::Transaction> t;
if ( sqlite::Transaction::transactionInProgress() == false )
t = m_ml->getConn()->newTransaction();
......
......@@ -25,6 +25,7 @@
#endif
#include "Thumbnail.h"
#include "utils/Cache.h"
namespace medialibrary
{
......@@ -78,6 +79,23 @@ Thumbnail::Origin Thumbnail::origin() const
return m_origin;
}
bool Thumbnail::setMrlFromPrimaryKey( MediaLibraryPtr ml,
Cache<std::shared_ptr<Thumbnail>>& thumbnail,
int64_t thumbnailId, std::string mrl )
{
auto lock = thumbnail.lock();
if ( thumbnail.isCached() == false )
{
thumbnail = Thumbnail::fetch( ml, thumbnailId );
if ( thumbnail.get() == nullptr )
{
LOG_WARN( "Failed to fetch thumbnail entity #", thumbnailId );
return false;
}
}
return thumbnail.get()->setMrl( std::move( mrl ) );
}
void Thumbnail::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ThumbnailTable::Name +
......
......@@ -29,6 +29,9 @@ namespace medialibrary
class Thumbnail;
template <typename T>
class Cache;
namespace policy
{
struct ThumbnailTable
......@@ -59,6 +62,17 @@ public:
bool setMrl( std::string mrl );
Origin origin() const;
/**
* @brief setMrlFromPrimaryKey Helper to set the thumbnail mrl based on a
* thumbnail ID.
* @param thumbnail The cached thumbnail entity. The value can be uncached
* in which case it will be fetched and cached.
* @param thumbnailId The thumbnail primary key
*/
static bool setMrlFromPrimaryKey( MediaLibraryPtr ml,
Cache<std::shared_ptr<Thumbnail>>& thumbnail,
int64_t thumbnailId, std::string mrl );
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Thumbnail> create( MediaLibraryPtr ml, std::string mrl,
Origin origin );
......
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