fixed crazy cost of search in file list tree/flat mode using filterProxyModel instrinsic filter system

This commit is contained in:
csoler 2018-04-22 17:15:40 +02:00
parent 63359e0801
commit 1e6e9dfd12
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
4 changed files with 198 additions and 141 deletions

View file

@ -30,6 +30,7 @@
#include "retroshare/rsfiles.h"
#include "retroshare/rspeers.h"
#include "util/misc.h"
#include "retroshare/rsexpr.h"
#include <QDir>
#include <QFileInfo>
@ -44,6 +45,7 @@
/*****
* #define RDM_DEBUG
****/
#define RDM_SEARCH_DEBUG
static const uint32_t FLAT_VIEW_MAX_REFS_PER_SECOND = 2000 ;
static const size_t FLAT_VIEW_MAX_REFS_TABLE_SIZE = 10000 ; //
@ -170,7 +172,7 @@ bool TreeStyle_RDM::hasChildren(const QModelIndex &parent) const
}
/* PERSON/DIR*/
#ifdef RDM_DEBUG
std::cerr << "lookup PER/DIR #" << details->count;
std::cerr << "lookup PER/DIR #" << details.count;
std::cerr << std::endl;
#endif
return (details.count > 0); /* do we have children? */
@ -229,7 +231,7 @@ int TreeStyle_RDM::rowCount(const QModelIndex &parent) const
/* else PERSON/DIR*/
#ifdef RDM_DEBUG
std::cerr << "lookup PER/DIR #" << details->count;
std::cerr << "lookup PER/DIR #" << details.count;
std::cerr << std::endl;
#endif
if ((details.type == DIR_TYPE_ROOT) && !_showEmpty && RemoteMode)
@ -367,11 +369,19 @@ const QIcon& RetroshareDirModel::getFlagsIcon(FileStorageFlags flags)
static_icons[n] = new QIcon(pix);
std::cerr << "Generated icon for flags " << std::hex << flags << std::endl;
std::cerr << "Generated icon for flags " << std::hex << flags << std::dec << std::endl;
}
return *static_icons[n] ;
}
QVariant RetroshareDirModel::filterRole(const DirDetails& details,int coln) const
{
if(mFilteredPointers.empty() || mFilteredPointers.find(details.ref) != mFilteredPointers.end())
return QString(RETROSHARE_DIR_MODEL_FILTER_STRING);
else
return QVariant();
}
QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) const
{
if(coln == COLUMN_FRIEND_ACCESS)
@ -803,9 +813,14 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
if (role == SortRole)
return sortRole(index,details,coln) ;
if (role == FilterRole)
return filterRole(details,coln) ;
return QVariant();
}
/****
//void RetroshareDirModel::getAgeIndicatorRec(const DirDetails &details, QString &ret) const {
// if (details.type == DIR_TYPE_FILE) {
@ -1026,7 +1041,7 @@ QModelIndex TreeStyle_RDM::parent( const QModelIndex & index ) const
}
#ifdef RDM_DEBUG
std::cerr << "success index(" << details->prow << ",0," << details->parent << ")";
std::cerr << "success index(" << details.prow << ",0," << details.parent << ")";
std::cerr << std::endl;
std::cerr << "Creating index 3 row=" << details.prow << ", column=" << 0 << ", ref=" << (void*)details.parent << std::endl;
@ -1339,10 +1354,10 @@ void RetroshareDirModel::getFileInfoFromIndexList(const QModelIndexList& list, s
#ifdef RDM_DEBUG
std::cerr << "::::::::::::FileRecommend:::: " << std::endl;
std::cerr << "Name: " << details->name << std::endl;
std::cerr << "Hash: " << details->hash << std::endl;
std::cerr << "Size: " << details->count << std::endl;
std::cerr << "Path: " << details->path << std::endl;
std::cerr << "Name: " << details.name << std::endl;
std::cerr << "Hash: " << details.hash << std::endl;
std::cerr << "Size: " << details.count << std::endl;
std::cerr << "Path: " << details.path << std::endl;
#endif
// Note: for directories, the returned hash, is the peer id, so if we collect
// dirs, we need to be a bit more conservative for the
@ -1449,6 +1464,70 @@ void RetroshareDirModel::getFilePaths(const QModelIndexList &list, std::list<std
#endif
}
void RetroshareDirModel::filterItems(const std::list<std::string>& keywords,uint32_t& found)
{
FileSearchFlags flags = RemoteMode?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL;
std::list<DirDetails> result_list ;
found = 0 ;
if(keywords.empty())
{
mFilteredPointers.clear();
return ;
}
else if(keywords.size() > 1)
{
RsRegularExpression::NameExpression exp(RsRegularExpression::ContainsAllStrings,keywords,true);
rsFiles->SearchBoolExp(&exp,result_list, flags) ;
}
else
rsFiles->SearchKeywords(keywords,result_list, flags) ;
#ifdef RDM_SEARCH_DEBUG
std::cerr << "Found " << result_list.size() << " results" << std::endl;
#endif
if(result_list.empty()) // in this case we dont clear the list of filtered items, so that we can keep the old filter list
return ;
mFilteredPointers.clear();
#ifdef RDM_SEARCH_DEBUG
std::cerr << "Found this result: " << std::endl;
#endif
// Then show only the ones we need
for(auto it(result_list.begin());it!=result_list.end();++it)
{
DirDetails& det(*it) ;
#ifdef RDM_SEARCH_DEBUG
std::cerr << (void*)(*it).ref << " name=\"" << det.name << "\" parents: " ;
#endif
void *p = det.ref ;
mFilteredPointers.insert(p) ;
++found ;
while(det.type == DIR_TYPE_FILE || det.type == DIR_TYPE_DIR)
{
p = det.parent ;
rsFiles->RequestDirDetails( p, det, flags);
#ifdef RDM_SEARCH_DEBUG
std::cerr << " " << (void*)p << "(" << (int)det.type << ")";
#endif
mFilteredPointers.insert(p) ;
}
#ifdef RDM_SEARCH_DEBUG
std::cerr << std::endl;
#endif
}
std::cerr << mFilteredPointers.size() << " pointers in filter set." << std::endl;
}
/* Drag and Drop Functionality */
QMimeData * RetroshareDirModel::mimeData ( const QModelIndexList & indexes ) const
{
@ -1468,10 +1547,10 @@ QMimeData * RetroshareDirModel::mimeData ( const QModelIndexList & indexes ) con
#ifdef RDM_DEBUG
std::cerr << "::::::::::::FileDrag:::: " << std::endl;
std::cerr << "Name: " << details->name << std::endl;
std::cerr << "Hash: " << details->hash << std::endl;
std::cerr << "Size: " << details->count << std::endl;
std::cerr << "Path: " << details->path << std::endl;
std::cerr << "Name: " << details.name << std::endl;
std::cerr << "Hash: " << details.hash << std::endl;
std::cerr << "Size: " << details.count << std::endl;
std::cerr << "Path: " << details.path << std::endl;
#endif
if (details.type != DIR_TYPE_FILE)