mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-23 05:44:45 -04:00
added a small trick to cache last request of RemoteDirModel::requestDirDetails
This commit is contained in:
parent
befeb44f07
commit
644c41e2e7
2 changed files with 35 additions and 4 deletions
|
@ -55,6 +55,9 @@ RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent)
|
||||||
setSupportedDragActions(Qt::CopyAction);
|
setSupportedDragActions(Qt::CopyAction);
|
||||||
#endif
|
#endif
|
||||||
treeStyle();
|
treeStyle();
|
||||||
|
|
||||||
|
mLastPointer = (void*)intptr_t(0xffffffff) ;
|
||||||
|
mLastRemote = false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// QAbstractItemModel::setSupportedDragActions() was replaced by virtual QAbstractItemModel::supportedDragActions()
|
// QAbstractItemModel::setSupportedDragActions() was replaced by virtual QAbstractItemModel::supportedDragActions()
|
||||||
|
@ -576,9 +579,7 @@ QVariant FlatStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails&
|
||||||
QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
|
QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "RetroshareDirModel::data(): " << index.internalPointer();
|
std::cerr << "RetroshareDirModel::data(): " << index.internalPointer() << std::endl;
|
||||||
std::cerr << ": ";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
@ -963,9 +964,33 @@ void RetroshareDirModel::postMods()
|
||||||
|
|
||||||
bool RetroshareDirModel::requestDirDetails(void *ref, bool remote,DirDetails& d) const
|
bool RetroshareDirModel::requestDirDetails(void *ref, bool remote,DirDetails& d) const
|
||||||
{
|
{
|
||||||
|
#ifdef RDM_DEBUG
|
||||||
|
std::cerr << "RequestDirDetails:: ref = " << ref << ", remote=" << remote << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// We look in cache and re-use the last result if the reference and remote are the same.
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
if(mLastPointer == ref && mLastRemote==remote && now < 2+mLastReq)
|
||||||
|
{
|
||||||
|
d = mLastDirDetails ;
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
FileSearchFlags flags = (remote) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL;
|
FileSearchFlags flags = (remote) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL;
|
||||||
|
|
||||||
return rsFiles->RequestDirDetails(ref, d, flags) ;
|
if(rsFiles->RequestDirDetails(ref, d, flags))
|
||||||
|
{
|
||||||
|
mLastReq = now ;
|
||||||
|
mLastPointer = ref ;
|
||||||
|
mLastRemote = remote ;
|
||||||
|
mLastDirDetails = d;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false ;
|
||||||
}
|
}
|
||||||
// const QMap<void*, DirDetailsVector>::const_iterator it = mCache.constFind(ref);
|
// const QMap<void*, DirDetailsVector>::const_iterator it = mCache.constFind(ref);
|
||||||
// if (it != mCache.constEnd()) {
|
// if (it != mCache.constEnd()) {
|
||||||
|
|
|
@ -151,6 +151,12 @@ class RetroshareDirModel : public QAbstractItemModel
|
||||||
mutable int nIndex;
|
mutable int nIndex;
|
||||||
mutable std::vector<RemoteIndex> indexSet;
|
mutable std::vector<RemoteIndex> indexSet;
|
||||||
|
|
||||||
|
// This material attempts to keep last request in cache, with no search cost.
|
||||||
|
|
||||||
|
mutable DirDetails mLastDirDetails ;
|
||||||
|
mutable void *mLastPointer ;
|
||||||
|
mutable bool mLastRemote ;
|
||||||
|
mutable time_t mLastReq;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class shows the classical hierarchical directory view of shared files
|
// This class shows the classical hierarchical directory view of shared files
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue