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

Cache label by value instead of primary key

parent b6a7492c
......@@ -7,7 +7,7 @@
#include "SqliteTools.h"
const std::string policy::LabelTable::Name = "Label";
const std::string policy::LabelTable::CacheColumn = "id_label";
const std::string policy::LabelTable::CacheColumn = "name";
Label::Label( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
......@@ -86,3 +86,14 @@ bool Label::createTable(sqlite3* dbConnection)
return SqliteTools::createTable( dbConnection, req.c_str() );
}
const std::string&policy::LabelCachePolicy::key( const std::shared_ptr<Label> self )
{
return self->name();
}
std::string policy::LabelCachePolicy::key(sqlite3_stmt* stmt)
{
return Traits<KeyType>::Load( stmt, 1 );
}
......@@ -5,6 +5,7 @@
#include <string>
class File;
class Label;
#include "ILabel.h"
#include "Cache.h"
......@@ -16,9 +17,17 @@ struct LabelTable
static const std::string Name;
static const std::string CacheColumn;
};
struct LabelCachePolicy
{
typedef std::string KeyType;
static const std::string& key( const std::shared_ptr<Label> self );
static std::string key( sqlite3_stmt* stmt );
};
}
class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable>
class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, policy::LabelCachePolicy>
{
public:
......
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