mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-29 01:33:46 +00:00
Refactoring in listdircontent.
This commit is contained in:
parent
0b6e6ad1d6
commit
76388be56e
4 changed files with 23 additions and 12 deletions
|
@ -115,7 +115,7 @@ namespace din {
|
|||
}
|
||||
|
||||
uint16_t EntryPath::level() const {
|
||||
return static_cast<uint16_t>(m_stack.size());
|
||||
return (m_stack.empty() ? static_cast<uint16_t>(0) : static_cast<uint16_t>(m_stack.size() - 1));
|
||||
}
|
||||
|
||||
const std::string& EntryPath::operator[] (std::size_t parIndex) const {
|
||||
|
@ -146,4 +146,8 @@ namespace din {
|
|||
boost::copy(boost::make_iterator_range(m_stack.begin() + 1, m_stack.end()), infix_ostream_iterator<std::string>(oss, "/"));
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
bool EntryPath::points_to_group(void) const {
|
||||
return m_stack.empty();
|
||||
}
|
||||
} //namespace din
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace din {
|
|||
uint16_t level ( void ) const;
|
||||
const std::string& operator[] ( std::size_t parIndex ) const;
|
||||
|
||||
bool points_to_group ( void ) const;
|
||||
uint32_t group_id ( void ) const;
|
||||
const std::string& group_id_as_string ( void ) const;
|
||||
std::string file_path ( void ) const;
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace din {
|
|||
}
|
||||
|
||||
//Requested item is not cached, so we need to query the db now
|
||||
if ("/" == curr_path) {
|
||||
if (parDir.points_to_group()) {
|
||||
auto sets_ids = m_db->sets();
|
||||
auto sets_info = m_db->set_details<SetDetail_ID, SetDetail_Desc, SetDetail_CreeationDate>(sets_ids);
|
||||
m_cache.push_back(std::make_pair(curr_path, db_result_to_vec(sets_info)));
|
||||
|
@ -92,12 +92,10 @@ namespace din {
|
|||
else {
|
||||
auto path_prefix = parDir.file_path();
|
||||
const auto set_id = parDir.group_id();
|
||||
auto files_info = m_db->file_details<FileDetail_Path>(set_id, parDir.level(), path_prefix);
|
||||
auto files_info = m_db->file_details<FileDetail_Path>(set_id, parDir.level() + 1, path_prefix);
|
||||
m_cache.push_back(std::make_pair(curr_path, db_result_to_vec(files_info)));
|
||||
}
|
||||
assert(not m_cache.empty());
|
||||
assert(m_cache.back().first == curr_path);
|
||||
return m_cache.back().second;
|
||||
return last_cached_item(curr_path);
|
||||
}
|
||||
|
||||
auto ListDirContent::ls ( EntryPath parDir, const std::string& parStartWith ) const -> const ListType& {
|
||||
|
@ -110,18 +108,24 @@ namespace din {
|
|||
return *cached_item;
|
||||
}
|
||||
|
||||
if ("/" == curr_path) {
|
||||
if (parDir.points_to_group()) {
|
||||
assert(false); //not implemented
|
||||
}
|
||||
else {
|
||||
assert(parDir.level() > 0);
|
||||
const auto set_id = parDir.group_id();
|
||||
const auto path_prefix = parDir.file_path();
|
||||
auto file_list = m_db->paths_starting_by(set_id, parDir.level() - 1, path_prefix);
|
||||
auto file_list = m_db->paths_starting_by(set_id, parDir.level(), path_prefix);
|
||||
m_cache.push_back(std::make_pair(curr_path, file_list));
|
||||
}
|
||||
assert(not m_cache.empty());
|
||||
assert(m_cache.back().first == curr_path);
|
||||
return m_cache.back().second;
|
||||
return last_cached_item(curr_path);
|
||||
}
|
||||
|
||||
auto ListDirContent::last_cached_item (const std::string& parCurrPath) const -> const ListType& {
|
||||
assert(not m_cache.empty());
|
||||
assert(m_cache.back().first == parCurrPath);
|
||||
#ifdef NDEBUG
|
||||
(void)parCurrPath;
|
||||
#endif
|
||||
return m_cache.back().second;
|
||||
};
|
||||
} //namespace din
|
||||
|
|
|
@ -38,6 +38,8 @@ namespace din {
|
|||
const ListType& ls ( EntryPath parDir, const std::string& parStartWith ) const;
|
||||
|
||||
private:
|
||||
const ListType& last_cached_item ( const std::string& parCurrPath ) const;
|
||||
|
||||
mutable boost::circular_buffer<CachedItemType> m_cache;
|
||||
DBSource* m_db;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue