changed: DirContainer - uses std::list instead of std::vector as the main container
we do not have to rebuild indexes after deleting some items added: DirContainer::DelById(long id) changed: Dirs::CheckRootDir() addes the root dir if there is no one added: Dirs::DeleteDir(long id) - deletes specified directory (and its contents) (from the cache and the database) added: Db::DelDirById(long id) - deletes a dir from the database and its first children added: standard function rm can delete directories git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@487 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -22,8 +22,8 @@ DirContainer::Iterator DirContainer::GetRoot()
|
||||
{
|
||||
if( !is_root )
|
||||
return table.end();
|
||||
|
||||
return table.begin() + root_index;
|
||||
|
||||
return root_iter;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,31 +54,26 @@ bool DirContainer::Empty()
|
||||
|
||||
void DirContainer::PushBack(const Item & item)
|
||||
{
|
||||
bool rebuild_indexes = false;
|
||||
|
||||
if( table.size() == table.capacity() )
|
||||
rebuild_indexes = true;
|
||||
|
||||
|
||||
if( item.parent_id == -1 )
|
||||
if( item.parent_id == -1 && is_root )
|
||||
{
|
||||
if( is_root )
|
||||
log << log1 << "DirCont: more than one root dir - skipped, id: " << item.id << logend;
|
||||
else
|
||||
{
|
||||
is_root = true;
|
||||
root_index = table.size();
|
||||
}
|
||||
log << log1 << "DirCont: more than one root dir - skipped, id: " << item.id << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
table.push_back(item);
|
||||
log << log2 << "DirCont: added dir, url: " << item.url << ", id: " << item.id << ", parent_id: " << item.parent_id << logend;
|
||||
|
||||
Iterator last_iter = table.insert(table.end(), item);
|
||||
|
||||
if( rebuild_indexes )
|
||||
RebuildIndexes();
|
||||
else
|
||||
AddIndexes( --table.end() );
|
||||
if( item.parent_id == -1 )
|
||||
{
|
||||
is_root = true;
|
||||
root_iter = last_iter;
|
||||
}
|
||||
|
||||
log << log2 << "DirCont: added dir, url: " << item.url << ", id: " << item.id << ", parent_id: " << item.parent_id << logend;
|
||||
|
||||
table_id.insert( std::make_pair(last_iter->id, last_iter) );
|
||||
table_parent.insert( std::make_pair(last_iter->parent_id, last_iter) );
|
||||
|
||||
log << log3 << "DirCont: added indexes to dir, id: " << last_iter->id << ", parent_id: " << last_iter->parent_id << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +85,7 @@ void DirContainer::Clear()
|
||||
table.clear();
|
||||
table_id.clear();
|
||||
table_parent.clear();
|
||||
is_root = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,34 +103,6 @@ return i->second;
|
||||
|
||||
|
||||
|
||||
|
||||
void DirContainer::AddIndexes(Iterator item)
|
||||
{
|
||||
table_id.insert( std::make_pair(item->id, item) );
|
||||
table_parent.insert( std::make_pair(item->parent_id, item) );
|
||||
|
||||
log << log2 << "DirCont: added indexes to dir, id: " << item->id << ", parent_id: " << item->parent_id << logend;
|
||||
}
|
||||
|
||||
|
||||
void DirContainer::RebuildIndexes()
|
||||
{
|
||||
Iterator i;
|
||||
|
||||
log << log2 << "DirCont: rebuilding indexes" << logend;
|
||||
|
||||
table_id.clear();
|
||||
table_parent.clear();
|
||||
|
||||
for(i=table.begin() ; i!=table.end() ; ++i)
|
||||
AddIndexes( i );
|
||||
|
||||
log << log2 << "DirCont: indexes rebuilt, table.size: " << table.size() << ", table_id.size: " << table_id.size() << ", table_parent.size: " << table_parent.size() << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DirContainer::ParentIterator DirContainer::ParentBegin()
|
||||
{
|
||||
return table_parent.begin();
|
||||
@@ -184,3 +152,56 @@ DirContainer::ParentIterator DirContainer::NextParent(ParentIterator i)
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool DirContainer::DelById(long id)
|
||||
{
|
||||
TableId::iterator i = table_id.find(id);
|
||||
|
||||
if( i == table_id.end() )
|
||||
{
|
||||
log << log1 << "DirCont: delete: there is no directory with id: " << id << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
long parent_id = i->second->parent_id;
|
||||
TableParent::iterator z = table_parent.lower_bound(parent_id);
|
||||
bool found = false;
|
||||
|
||||
for( ; z != table_parent.end() && z->first == parent_id ; ++z )
|
||||
{
|
||||
if( z->second == i->second )
|
||||
{
|
||||
log << log2 << "DirCont: deleted directory id: " << id << ", url: " << i->second->url;
|
||||
|
||||
if( i->second->parent_id == -1 )
|
||||
{
|
||||
log << log2 << " (root directory)";
|
||||
is_root = false;
|
||||
}
|
||||
|
||||
log << log2 << logend;
|
||||
|
||||
table.erase(i->second);
|
||||
|
||||
log << log3 << "DirCont: deleted indexes into directory id: " << id << logend;
|
||||
table_id.erase(i);
|
||||
table_parent.erase(z);
|
||||
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
log << log1 << "DirCont: can't find an index_parent into directory id: " << id << ", url: " << i->second->url << " (deleting skipped)" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user