Browse Source

- Found a way not to use FullAllocationMode list in order to save memory in cpu

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
27e76962d1
  1. 20
      src/bittorrent.cpp
  2. 2
      src/bittorrent.h
  3. 6
      src/properties_imp.cpp
  4. 11
      src/qtorrenthandle.cpp
  5. 1
      src/qtorrenthandle.h

20
src/bittorrent.cpp

@ -186,12 +186,8 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) {
trackersErrors.remove(hash); trackersErrors.remove(hash);
// Remove it from ratio table // Remove it from ratio table
ratioData.remove(hash); ratioData.remove(hash);
int index = fullAllocationModeList.indexOf(hash);
if(index != -1) {
fullAllocationModeList.removeAt(index);
}
// Remove it from pausedTorrents list // Remove it from pausedTorrents list
index = pausedTorrents.indexOf(hash); int index = pausedTorrents.indexOf(hash);
if(index != -1) { if(index != -1) {
pausedTorrents.removeAt(index); pausedTorrents.removeAt(index);
} }
@ -424,10 +420,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
// Adding files to bittorrent session // Adding files to bittorrent session
if(has_filtered_files(hash)) { if(has_filtered_files(hash)) {
h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, false, true); h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, false, true);
int index = fullAllocationModeList.indexOf(hash);
if(index == -1) {
fullAllocationModeList << hash;
}
qDebug(" -> Full allocation mode"); qDebug(" -> Full allocation mode");
}else{ }else{
h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, true, true); h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, true, true);
@ -1109,10 +1101,6 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) {
QString fileName = h.name(); QString fileName = h.name();
QString hash = h.hash(); QString hash = h.hash();
torrent_info t = h.get_torrent_info(); torrent_info t = h.get_torrent_info();
int index = fullAllocationModeList.indexOf(hash);
if(index == -1) {
fullAllocationModeList << hash;
}
qDebug("Reloading torrent: %s", fileName.toUtf8().data()); qDebug("Reloading torrent: %s", fileName.toUtf8().data());
entry resumeData; entry resumeData;
// Checking if torrentBackup Dir exists // Checking if torrentBackup Dir exists
@ -1169,12 +1157,6 @@ session_status bittorrent::getSessionStatus() const{
return s->status(); return s->status();
} }
bool bittorrent::inFullAllocationMode(QString hash) const{
if(fullAllocationModeList.indexOf(hash) != -1)
return true;
return false;
}
QString bittorrent::getSavePath(QString hash) { QString bittorrent::getSavePath(QString hash) {
QFile savepath_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".savepath"); QFile savepath_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".savepath");
QByteArray line; QByteArray line;

2
src/bittorrent.h

@ -53,7 +53,6 @@ class bittorrent : public QObject{
QHash<QString, qlonglong> ETAs; QHash<QString, qlonglong> ETAs;
QHash<QString, QPair<size_type,size_type> > ratioData; QHash<QString, QPair<size_type,size_type> > ratioData;
QTimer *ETARefresher; QTimer *ETARefresher;
QStringList fullAllocationModeList;
QHash<QString, QList<QPair<QString, QString> > > trackersErrors; QHash<QString, QList<QPair<QString, QString> > > trackersErrors;
deleteThread *deleter; deleteThread *deleter;
QStringList pausedTorrents; QStringList pausedTorrents;
@ -77,7 +76,6 @@ class bittorrent : public QObject{
int getListenPort() const; int getListenPort() const;
QStringList getTorrentsToPauseAfterChecking() const; QStringList getTorrentsToPauseAfterChecking() const;
long getETA(QString hash) const; long getETA(QString hash) const;
bool inFullAllocationMode(QString hash) const;
float getRealRatio(QString hash) const; float getRealRatio(QString hash) const;
session* getSession() const; session* getSession() const;
QList<QPair<QString, QString> > getTrackersErrors(QString hash) const; QList<QPair<QString, QString> > getTrackersErrors(QString hash) const;

6
src/properties_imp.cpp

@ -589,10 +589,12 @@ void properties::savePiecesPriorities(){
pieces_file.write(misc::toQByteArray(priority)+"\n"); pieces_file.write(misc::toQByteArray(priority)+"\n");
} }
pieces_file.close(); pieces_file.close();
if(hasFilteredFiles && !BTSession->inFullAllocationMode(hash)){ // If h.has_filtered_pieces() s true, then the torrent
// is already in full allocation mode, no need to
// reload it.
if(hasFilteredFiles && !h.has_filtered_pieces()){
BTSession->pauseAndReloadTorrent(h); BTSession->pauseAndReloadTorrent(h);
} }
BTSession->loadFilesPriorities(h);
emit filteredFilesChanged(hash); emit filteredFilesChanged(hash);
has_filtered_files = hasFilteredFiles; has_filtered_files = hasFilteredFiles;
} }

11
src/qtorrenthandle.cpp

@ -131,7 +131,7 @@ size_type QTorrentHandle::actual_size() const{
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
size_type size = 0; size_type size = 0;
std::vector<int> piece_priorities = h.piece_priorities(); std::vector<int> piece_priorities = h.piece_priorities();
for(unsigned int i = 0; i<piece_priorities.size(); ++i){ for(unsigned int i = 0; i<piece_priorities.size(); ++i) {
if(piece_priorities[i]) if(piece_priorities[i])
size += h.get_torrent_info().piece_size(i); size += h.get_torrent_info().piece_size(i);
} }
@ -139,6 +139,15 @@ size_type QTorrentHandle::actual_size() const{
return size; return size;
} }
bool QTorrentHandle::has_filtered_pieces() const {
Q_ASSERT(h.is_valid());
std::vector<int> piece_priorities = h.piece_priorities();
for(unsigned int i = 0; i<piece_priorities.size(); ++i) {
if(!piece_priorities[i]) return true;
}
return false;
}
int QTorrentHandle::download_limit() const { int QTorrentHandle::download_limit() const {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
return h.download_limit(); return h.download_limit();

1
src/qtorrenthandle.h

@ -56,6 +56,7 @@ class QTorrentHandle {
QString current_tracker() const; QString current_tracker() const;
bool is_valid() const; bool is_valid() const;
bool is_paused() const; bool is_paused() const;
bool has_filtered_pieces() const;
// size_type total_size() const; // size_type total_size() const;
size_type total_done() const; size_type total_done() const;
float download_payload_rate() const; float download_payload_rate() const;

Loading…
Cancel
Save