diff --git a/src/lib/data/indexer/IndexerCommandList.cpp b/src/lib/data/indexer/IndexerCommandList.cpp index f42f7b01..45b64166 100644 --- a/src/lib/data/indexer/IndexerCommandList.cpp +++ b/src/lib/data/indexer/IndexerCommandList.cpp @@ -3,6 +3,8 @@ #include #include +#include "utility/file/FileSystem.h" + void IndexerCommandList::addCommand(std::shared_ptr command) { std::lock_guard lock(m_commandsMutex); @@ -16,9 +18,29 @@ size_t IndexerCommandList::size() const void IndexerCommandList::shuffle() { - srand(unsigned(time(NULL))); std::lock_guard lock(m_commandsMutex); - std::random_shuffle(m_commands.begin(), m_commands.end()); + + typedef std::pair> PairType; + + std::vector sourceFileSizesToCommands; + for (std::shared_ptr command: m_commands) + { + sourceFileSizesToCommands.push_back(std::make_pair(FileSystem::getFileByteSize(command->getSourceFilePath()), command)); + } + std::sort(sourceFileSizesToCommands.begin(), sourceFileSizesToCommands.end(), [](const PairType& p, const PairType& q){ return p.first > q.first; }); + + if (sourceFileSizesToCommands.size() > 2) + { + srand(unsigned(time(NULL))); + std::random_shuffle(sourceFileSizesToCommands.begin(), sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2); + std::random_shuffle(sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2, sourceFileSizesToCommands.end()); + } + + m_commands.clear(); + for (const PairType& pair: sourceFileSizesToCommands) + { + m_commands.push_back(pair.second); + } } std::shared_ptr IndexerCommandList::consumeCommand() diff --git a/src/lib/utility/file/FileSystem.cpp b/src/lib/utility/file/FileSystem.cpp index e8d8751d..9383f372 100644 --- a/src/lib/utility/file/FileSystem.cpp +++ b/src/lib/utility/file/FileSystem.cpp @@ -138,6 +138,11 @@ std::vector FileSystem::getFileInfosFromPaths( return files; } +unsigned long long FileSystem::getFileByteSize(const FilePath& filePath) +{ + return boost::filesystem::file_size(filePath.path()); +} + TimePoint FileSystem::getLastWriteTime(const FilePath& filePath) { boost::posix_time::ptime lastWriteTime; diff --git a/src/lib/utility/file/FileSystem.h b/src/lib/utility/file/FileSystem.h index 066ddaa1..689654a0 100644 --- a/src/lib/utility/file/FileSystem.h +++ b/src/lib/utility/file/FileSystem.h @@ -18,6 +18,8 @@ public: static std::vector getFileInfosFromPaths( const std::vector& paths, const std::vector& fileExtensions, bool followSymLinks = true); + static unsigned long long getFileByteSize(const FilePath& filePath); + static TimePoint getLastWriteTime(const FilePath& filePath); static std::string getTimeStringNow();