Merge pull request #579 from csoler/v0.6-FileListsOptim

fixed constant updating of flat dir model. Had to limit to at most 10…
This commit is contained in:
Cyril Soler 2016-11-21 00:17:10 +01:00 committed by GitHub
commit 5af54254ca
2 changed files with 42 additions and 27 deletions

View File

@ -45,6 +45,10 @@
* #define RDM_DEBUG * #define RDM_DEBUG
****/ ****/
static const uint32_t FLAT_VIEW_MAX_REFS_PER_SECOND = 2000 ;
static const uint32_t FLAT_VIEW_MAX_REFS_TABLE_SIZE = 10000 ; //
static const uint32_t FLAT_VIEW_MIN_DELAY_BETWEEN_UPDATES = 120 ; // dont rebuild ref list more than every 2 mins.
RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent) RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent)
: QAbstractItemModel(parent), : QAbstractItemModel(parent),
ageIndicator(IND_ALWAYS), ageIndicator(IND_ALWAYS),
@ -73,14 +77,7 @@ static bool isNewerThanEpoque(uint32_t ts)
return ts > 0 ; // this should be conservative enough return ts > 0 ; // this should be conservative enough
} }
void FlatStyle_RDM::update()
{
if(_needs_update)
{
preMods() ;
postMods() ;
}
}
void RetroshareDirModel::treeStyle() void RetroshareDirModel::treeStyle()
{ {
categoryIcon.addPixmap(QPixmap(":/images/folder16.png"), categoryIcon.addPixmap(QPixmap(":/images/folder16.png"),
@ -480,6 +477,25 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
return QVariant(); return QVariant();
} /* end of DisplayRole */ } /* end of DisplayRole */
FlatStyle_RDM::FlatStyle_RDM(bool mode)
: RetroshareDirModel(mode), _ref_mutex("Flat file list")
{
_needs_update = true ;
{
RS_STACK_MUTEX(_ref_mutex) ;
_last_update = 0 ;
}
}
void FlatStyle_RDM::update()
{
if(_needs_update)
{
preMods() ;
postMods() ;
}
}
QString FlatStyle_RDM::computeDirectoryPath(const DirDetails& details) const QString FlatStyle_RDM::computeDirectoryPath(const DirDetails& details) const
{ {
QString dir ; QString dir ;
@ -1429,6 +1445,11 @@ TreeStyle_RDM::~TreeStyle_RDM()
} }
void FlatStyle_RDM::postMods() void FlatStyle_RDM::postMods()
{ {
time_t now = time(NULL);
if(_last_update + FLAT_VIEW_MIN_DELAY_BETWEEN_UPDATES > now)
return ;
if(visible()) if(visible())
{ {
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
@ -1437,7 +1458,8 @@ void FlatStyle_RDM::postMods()
RS_STACK_MUTEX(_ref_mutex) ; RS_STACK_MUTEX(_ref_mutex) ;
_ref_stack.clear() ; _ref_stack.clear() ;
_ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory _ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory
_needs_update = false ; _ref_entries.clear();
_last_update = now;
} }
QTimer::singleShot(100,this,SLOT(updateRefs())) ; QTimer::singleShot(100,this,SLOT(updateRefs())) ;
} }
@ -1449,23 +1471,18 @@ void FlatStyle_RDM::updateRefs()
{ {
if(RsAutoUpdatePage::eventsLocked()) if(RsAutoUpdatePage::eventsLocked())
{ {
_needs_update = true ; QTimer::singleShot(5000,this,SLOT(updateRefs())) ;
return ; return ;
} }
RetroshareDirModel::preMods() ; RetroshareDirModel::preMods() ;
static const uint32_t MAX_REFS_PER_SECOND = 2000 ;
uint32_t nb_treated_refs = 0 ; uint32_t nb_treated_refs = 0 ;
{ {
RS_STACK_MUTEX(_ref_mutex) ; RS_STACK_MUTEX(_ref_mutex) ;
_ref_entries.clear() ;
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl;
while(!_ref_stack.empty()) while(!_ref_stack.empty())
{ {
void *ref = _ref_stack.back() ; void *ref = _ref_stack.back() ;
@ -1486,10 +1503,14 @@ void FlatStyle_RDM::updateRefs()
for(uint32_t i=0;i<details.children.size();++i) for(uint32_t i=0;i<details.children.size();++i)
_ref_stack.push_back(details.children[i].ref) ; _ref_stack.push_back(details.children[i].ref) ;
} }
if(++nb_treated_refs > MAX_REFS_PER_SECOND) // we've done enough, let's give back hand to
{ // the user and setup a timer to finish the job later.
_needs_update = true ;
// Limit the size of the table to display, otherwise it becomes impossible to Qt.
if(_ref_entries.size() > FLAT_VIEW_MAX_REFS_TABLE_SIZE)
return ;
if(++nb_treated_refs > FLAT_VIEW_MAX_REFS_PER_SECOND) // we've done enough, let's give back hand to
{ // the user and setup a timer to finish the job later.
if(visible()) if(visible())
QTimer::singleShot(2000,this,SLOT(updateRefs())) ; QTimer::singleShot(2000,this,SLOT(updateRefs())) ;
else else
@ -1497,10 +1518,7 @@ void FlatStyle_RDM::updateRefs()
break ; break ;
} }
} }
std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl; std::cerr << "reference tab contains " << std::dec << _ref_entries.size() << " files" << std::endl;
if(_ref_stack.empty())
_needs_update = false ;
} }
RetroshareDirModel::postMods() ; RetroshareDirModel::postMods() ;

View File

@ -199,11 +199,7 @@ class FlatStyle_RDM: public RetroshareDirModel
Q_OBJECT Q_OBJECT
public: public:
FlatStyle_RDM(bool mode) FlatStyle_RDM(bool mode);
: RetroshareDirModel(mode), _ref_mutex("Flat file list")
{
_needs_update = true ;
}
virtual ~FlatStyle_RDM() ; virtual ~FlatStyle_RDM() ;
@ -233,6 +229,7 @@ class FlatStyle_RDM: public RetroshareDirModel
std::vector<void *> _ref_entries ;// used to store the refs to display std::vector<void *> _ref_entries ;// used to store the refs to display
std::vector<void *> _ref_stack ; // used to store the refs to update std::vector<void *> _ref_stack ; // used to store the refs to update
bool _needs_update ; bool _needs_update ;
time_t _last_update ;
}; };