mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #569 from csoler/v0.6-FileListsOptim
V0.6 file lists optim
This commit is contained in:
commit
cc452ae51e
@ -204,6 +204,8 @@ public:
|
||||
* \return
|
||||
*/
|
||||
time_t& lastSweepTime() { return mLastSweepTime ; }
|
||||
|
||||
const std::string& filename() const { return mFileName ; }
|
||||
private:
|
||||
time_t mLastSavedTime ;
|
||||
time_t mLastSweepTime ;
|
||||
|
@ -31,6 +31,9 @@ static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 min
|
||||
static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed.
|
||||
static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec.
|
||||
|
||||
static const uint32_t DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR = 60*24*86400 ; // delete non empty remoe directories after 60 days of inactivity
|
||||
static const uint32_t DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR = 5*24*86400 ; // delete empty remote directories after 5 days of inactivity
|
||||
|
||||
static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time
|
||||
static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files
|
||||
static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch
|
||||
|
@ -440,10 +440,30 @@ void p3FileDatabase::cleanup()
|
||||
for(std::list<RsPeerId>::const_iterator it(friend_lst.begin());it!=friend_lst.end();++it)
|
||||
friend_set.insert(*it) ;
|
||||
}
|
||||
time_t now = time(NULL);
|
||||
|
||||
for(uint32_t i=0;i<mRemoteDirectories.size();++i)
|
||||
if(mRemoteDirectories[i] != NULL && friend_set.find(mRemoteDirectories[i]->peerId()) == friend_set.end())
|
||||
if(mRemoteDirectories[i] != NULL)
|
||||
{
|
||||
time_t recurs_mod_time ;
|
||||
mRemoteDirectories[i]->getDirectoryRecursModTime(0,recurs_mod_time) ;
|
||||
|
||||
time_t last_contact = 0 ;
|
||||
RsPeerDetails pd ;
|
||||
if(rsPeers->getPeerDetails(mRemoteDirectories[i]->peerId(),pd))
|
||||
last_contact = pd.lastConnect ;
|
||||
|
||||
// We remove directories in the following situations:
|
||||
// - the peer is not a friend
|
||||
// - the dir list is non empty but the peer is offline since more than 60 days
|
||||
// - the dir list is empty and the peer is ffline since more than 5 days
|
||||
|
||||
bool should_remove = friend_set.find(mRemoteDirectories[i]->peerId()) == friend_set.end()
|
||||
|| (recurs_mod_time == 0 && last_contact + DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR < now )
|
||||
|| (recurs_mod_time != 0 && last_contact + DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR < now );
|
||||
|
||||
if(!should_remove)
|
||||
continue ;
|
||||
|
||||
#ifdef DEBUG_P3FILELISTS
|
||||
P3FILELISTS_DEBUG() << " removing file list of non friend " << mRemoteDirectories[i]->peerId() << std::endl;
|
||||
@ -455,6 +475,10 @@ void p3FileDatabase::cleanup()
|
||||
|
||||
mFriendIndexMap.erase(mRemoteDirectories[i]->peerId());
|
||||
|
||||
// also remove the existing file
|
||||
|
||||
remove(mRemoteDirectories[i]->filename().c_str()) ;
|
||||
|
||||
delete mRemoteDirectories[i];
|
||||
mRemoteDirectories[i] = NULL ;
|
||||
|
||||
@ -476,8 +500,10 @@ void p3FileDatabase::cleanup()
|
||||
//
|
||||
for(std::set<RsPeerId>::const_iterator it(friend_set.begin());it!=friend_set.end();++it)
|
||||
{
|
||||
// Check if a remote directory exists for that friend, possibly creating the index.
|
||||
locked_getFriendIndex(*it) ;
|
||||
// Check if a remote directory exists for that friend, possibly creating the index if the file does not but the friend is online.
|
||||
|
||||
if(rsPeers->isOnline(*it) || RsDirUtil::fileExists(makeRemoteFileName(*it)))
|
||||
locked_getFriendIndex(*it) ;
|
||||
}
|
||||
|
||||
// cancel existing requests for which the peer is offline
|
||||
@ -485,8 +511,6 @@ void p3FileDatabase::cleanup()
|
||||
std::set<RsPeerId> online_peers ;
|
||||
mServCtrl->getPeersConnected(getServiceInfo().mServiceType, online_peers) ;
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
for(std::map<DirSyncRequestId,DirSyncRequestData>::iterator it = mPendingSyncRequests.begin();it!=mPendingSyncRequests.end();)
|
||||
if(online_peers.find(it->second.peer_id) == online_peers.end() || it->second.request_TS + DELAY_BEFORE_DROP_REQUEST < now)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user