improved cost of search usign temporization. Removed some debugging outputs from RetroShareLink

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4027 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-02-09 21:44:49 +00:00
parent 081cfee461
commit 62c7f815fc
3 changed files with 75 additions and 33 deletions

View File

@ -35,7 +35,7 @@
#include <retroshare/rsfiles.h>
#include <retroshare/rspeers.h>
#define DEBUG_RSLINK 1
//#define DEBUG_RSLINK 1
#define HOST_FILE "file"
#define HOST_PERSON "person"
@ -344,7 +344,9 @@ bool RetroShareLink::process(int flag)
case TYPE_FILE:
{
#ifdef DEBUG_RSLINK
std::cerr << " RetroShareLink::process FileRequest : fileName : " << name().toUtf8().constData() << ". fileHash : " << hash().toStdString() << ". fileSize : " << size() << std::endl;
#endif
// Get a list of available direct sources, in case the file is browsable only.
std::list<std::string> srcIds;
@ -353,7 +355,9 @@ bool RetroShareLink::process(int flag)
for(std::list<TransferInfo>::const_iterator it(finfo.peers.begin());it!=finfo.peers.end();++it)
{
#ifdef DEBUG_RSLINK
std::cerr << " adding peerid " << (*it).peerId << std::endl ;
#endif
srcIds.push_back((*it).peerId) ;
}
@ -376,7 +380,9 @@ bool RetroShareLink::process(int flag)
case TYPE_PERSON:
{
#ifdef DEBUG_RSLINK
std::cerr << " RetroShareLink::process FriendRequest : name : " << name().toStdString() << ". id : " << hash().toStdString() << std::endl;
#endif
RsPeerDetails detail;
if (rsPeers->getPeerDetails(hash().toStdString(), detail)) {
@ -477,11 +483,15 @@ void RSLinkClipboard::parseClipboard(std::vector<RetroShareLink> &links)
if(!already)
{
links.push_back(link) ;
#ifdef DEBUG_RSLINK
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
#endif
}
}
#ifdef DEBUG_RSLINK
else
std::cerr << "invalid link" << std::endl ;
#endif
pos += rx.matchedLength();
}

View File

@ -21,6 +21,7 @@
#include <QMessageBox>
#include <QDir>
#include <QTimer>
#include "SearchDialog.h"
#include "RetroShareLink.h"
@ -82,6 +83,7 @@ SearchDialog::SearchDialog(QWidget *parent)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
_queueIsAlreadyTakenCareOf = false ;
ui.lineEdit->setFocus();
ui.lineEdit->setToolTip(tr("Enter a keyword here (at least 3 char long)"));
@ -599,6 +601,26 @@ void SearchDialog::searchKeywords()
void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
{
searchResultsQueue.push_back(std::pair<qulonglong,FileDetail>(search_id,file)) ;
if(!_queueIsAlreadyTakenCareOf)
{
QTimer::singleShot(100,this,SLOT(processResultQueue())) ;
_queueIsAlreadyTakenCareOf = true ;
}
}
void SearchDialog::processResultQueue()
{
int nb_treated_elements = 0 ;
while(!searchResultsQueue.empty() && nb_treated_elements++ < 500)
{
qulonglong search_id = searchResultsQueue.back().first ;
FileDetail file = searchResultsQueue.back().second ;
searchResultsQueue.pop_back() ;
/* which extensions do we use? */
std::string txt = ui.lineEdit->text().toStdString();
#ifdef DEBUG
@ -633,6 +655,11 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
}
}
}
if(!searchResultsQueue.empty())
QTimer::singleShot(1000,this,SLOT(processResultQueue())) ;
else
_queueIsAlreadyTakenCareOf = false ;
}
void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item)
{
@ -815,11 +842,12 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
QString sid_hexa = QString::number(searchId,16) ;
for(int i = 0; i < items; i++)
if(ui.searchResultWidget->topLevelItem(i)->text(SR_HASH_COL) == QString::fromStdString(file.hash)
&& ui.searchResultWidget->topLevelItem(i)->text(SR_SEARCH_ID_COL) == sid_hexa)
QList<QTreeWidgetItem*> itms = ui.searchResultWidget->findItems(QString::fromStdString(file.hash),Qt::MatchExactly,SR_HASH_COL) ;
for(QList<QTreeWidgetItem*>::const_iterator it(itms.begin());it!=itms.end();++it)
if((*it)->text(SR_SEARCH_ID_COL) == sid_hexa)
{
QString resultCount = ui.searchResultWidget->topLevelItem(i)->text(SR_ID_COL);
QString resultCount = (*it)->text(SR_ID_COL);
QStringList modifiedResultCount = resultCount.split("/", QString::SkipEmptyParts);
if(searchType == FRIEND_SEARCH)
{
@ -833,8 +861,8 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
}
anonymousSource = anonymousSource + friendSource;
modifiedResult = QString::number(friendSource) + "/" + QString::number(anonymousSource);
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,modifiedResult);
QTreeWidgetItem *item = ui.searchResultWidget->topLevelItem(i);
(*it)->setText(SR_ID_COL,modifiedResult);
QTreeWidgetItem *item = (*it);
found = true ;
int sources = friendSource + anonymousSource ;
if ( sources < 1)

View File

@ -49,6 +49,7 @@ private slots:
/** Create the context popup menu and it's submenus */
void searchtableWidgetCostumPopupMenu( QPoint point );
void processResultQueue();
void searchtableWidget2CostumPopupMenu( QPoint point );
void download();
@ -130,6 +131,9 @@ QTreeWidget *searchtablewidget2;
/** Qt Designer generated object */
Ui::SearchDialog ui;
bool _queueIsAlreadyTakenCareOf ;
std::vector<std::pair<qulonglong,FileDetail> > searchResultsQueue ;
};
#endif