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

Labels: Do not store a list of files.

parent d49b4401
......@@ -13,7 +13,7 @@ class ILabel
virtual unsigned int id() const = 0;
virtual const std::string& name() = 0;
virtual std::vector<FilePtr>& files() = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
};
#endif // ILABEL_H
......@@ -12,7 +12,6 @@ unsigned int Label::* const policy::LabelTable::PrimaryKey = &Label::m_id;
Label::Label( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
, m_files( NULL )
{
m_id = sqlite3_column_int( stmt, 0 );
m_name = (const char*)sqlite3_column_text( stmt, 1 );
......@@ -22,7 +21,6 @@ Label::Label( const std::string& name )
: m_dbConnection( NULL )
, m_id( 0 )
, m_name( name )
, m_files( NULL )
{
}
......@@ -37,17 +35,12 @@ const std::string& Label::name()
return m_name;
}
std::vector<FilePtr>& Label::files()
bool Label::files( std::vector<FilePtr>& files )
{
if ( m_files == nullptr )
{
m_files = new std::vector<std::shared_ptr<IFile>>;
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?";
SqliteTools::fetchAll<File>( m_dbConnection, req.c_str(), *m_files, m_id );
}
return *m_files;
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?";
return SqliteTools::fetchAll<File>( m_dbConnection, req.c_str(), files, m_id );
}
LabelPtr Label::create( sqlite3* dbConnection, const std::string& name )
......
......@@ -39,7 +39,7 @@ class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, pol
public:
virtual unsigned int id() const;
virtual const std::string& name();
virtual std::vector<FilePtr>& files();
virtual bool files( std::vector<FilePtr>& files );
static LabelPtr create(sqlite3* dbConnection, const std::string& name );
static bool createTable( sqlite3* dbConnection );
......@@ -47,7 +47,6 @@ class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, pol
sqlite3* m_dbConnection;
unsigned int m_id;
std::string m_name;
std::vector<std::shared_ptr<IFile>>* m_files;
friend class Cache<Label, ILabel, policy::LabelTable>;
friend class policy::LabelTable;
......
......@@ -104,8 +104,13 @@ TEST_F( Labels, Files )
f2->addLabel( l2 );
f3->addLabel( l1 );
auto label1Files = l1->files();
auto label2Files = l2->files();
std::vector<FilePtr> label1Files;
std::vector<FilePtr> label2Files;
bool res = l1->files( label1Files );
ASSERT_TRUE( res );
res = l2->files( label2Files );
ASSERT_TRUE( res );
ASSERT_EQ( label1Files.size(), 2u );
ASSERT_EQ( label2Files.size(), 1u );
......
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