logic: sort custom indexer commands by indexed file size and name

This commit is contained in:
mlangkabel
2019-05-21 17:23:03 +02:00
parent 0fb7fe719a
commit 4d6cb464c4
4 changed files with 52 additions and 43 deletions
@@ -16,6 +16,7 @@
#include "TextAccess.h"
#include "utility.h"
#include "utilityApp.h"
#include "utilityFile.h"
#include "utilityString.h"
TaskExecuteCustomCommands::TaskExecuteCustomCommands(
@@ -42,7 +43,7 @@ void TaskExecuteCustomCommands::doEnter(std::shared_ptr<Blackboard> blackboard)
if (m_indexerCommandProvider)
{
for (const FilePath& sourceFilePath : m_indexerCommandProvider->getAllSourceFilePaths())
for (const FilePath& sourceFilePath : utility::partitionFilePathsBySize(m_indexerCommandProvider->getAllSourceFilePaths(), 2))
{
if (std::shared_ptr<IndexerCommandCustom> indexerCommand =
std::dynamic_pointer_cast<IndexerCommandCustom>(m_indexerCommandProvider->consumeCommandForSourceFilePath(sourceFilePath)))
@@ -67,6 +68,9 @@ void TaskExecuteCustomCommands::doEnter(std::shared_ptr<Blackboard> blackboard)
}
}
}
// reverse because we pull elements from the back of these vectors
std::reverse(m_parallelCommands.begin(), m_parallelCommands.end());
std::reverse(m_serialCommands.begin(), m_serialCommands.end());
}
}
@@ -1,9 +1,10 @@
#include "TaskFillIndexerCommandQueue.h"
#include "IndexerCommandProvider.h"
#include "FileSystem.h"
#include "logging.h"
#include "Blackboard.h"
#include "FileSystem.h"
#include "IndexerCommandProvider.h"
#include "logging.h"
#include "utilityFile.h"
TaskFillIndexerCommandsQueue::TaskFillIndexerCommandsQueue(
const std::string& appUUID,
@@ -18,48 +19,11 @@ TaskFillIndexerCommandsQueue::TaskFillIndexerCommandsQueue(
void TaskFillIndexerCommandsQueue::doEnter(std::shared_ptr<Blackboard> blackboard)
{
typedef std::pair<unsigned long long int, FilePath> PairType;
std::vector<PairType> sourceFileSizesToCommands;
{
std::vector<FilePath> allSourceFilePaths;
{
std::lock_guard<std::mutex> lock(m_commandsMutex);
allSourceFilePaths = m_indexerCommandProvider->getAllSourceFilePaths();
}
for (const FilePath& path : allSourceFilePaths)
{
if (path.exists())
{
sourceFileSizesToCommands.push_back(std::make_pair(FileSystem::getFileByteSize(path), path));
}
else
{
sourceFileSizesToCommands.push_back(std::make_pair(1, path));
}
}
std::sort(sourceFileSizesToCommands.begin(), sourceFileSizesToCommands.end(), [](const PairType& p, const PairType& q) { return p.first > q.first; });
if (sourceFileSizesToCommands.size() > 2)
{
std::sort(
sourceFileSizesToCommands.begin(),
sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2,
[](const PairType& p, const PairType& q) { return p.second.wstr() < q.second.wstr(); }
);
std::sort(
sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() / 2,
sourceFileSizesToCommands.end(),
[](const PairType& p, const PairType& q) { return p.second.wstr() < q.second.wstr(); }
);
}
}
{
std::lock_guard<std::mutex> lock(m_commandsMutex);
for (const PairType &pair : sourceFileSizesToCommands)
for (const FilePath& filePath : utility::partitionFilePathsBySize(m_indexerCommandProvider->getAllSourceFilePaths(), 2))
{
m_filePathQueue.emplace(pair.second);
m_filePathQueue.emplace(filePath);
}
}
+39
View File
@@ -1,9 +1,48 @@
#include "utilityFile.h"
#include "FilePath.h"
#include "FileSystem.h"
#include "utility.h"
std::vector<FilePath> utility::partitionFilePathsBySize(std::vector<FilePath> filePaths, int partitionCount)
{
typedef std::pair<unsigned long long int, FilePath> PairType;
std::vector<PairType> sourceFileSizesToCommands;
for (const FilePath& path : filePaths)
{
if (path.exists())
{
sourceFileSizesToCommands.push_back(std::make_pair(FileSystem::getFileByteSize(path), path));
}
else
{
sourceFileSizesToCommands.push_back(std::make_pair(1, path));
}
}
std::sort(sourceFileSizesToCommands.begin(), sourceFileSizesToCommands.end(), [](const PairType& p, const PairType& q) { return p.first > q.first; });
if (0 < partitionCount && partitionCount < sourceFileSizesToCommands.size())
{
for (int i = 0; i < partitionCount; i++)
{
std::sort(
sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() * i / partitionCount,
sourceFileSizesToCommands.begin() + sourceFileSizesToCommands.size() * (i + 1) / partitionCount,
[](const PairType& p, const PairType& q) { return p.second.wstr() < q.second.wstr(); }
);
}
}
std::vector<FilePath> sortedFilePaths;
for (const PairType &pair : sourceFileSizesToCommands)
{
sortedFilePaths.push_back(pair.second);
}
return sortedFilePaths;
}
std::vector<FilePath> utility::getTopLevelPaths(const std::vector<FilePath>& paths)
{
return utility::getTopLevelPaths(utility::toSet(paths));
+2
View File
@@ -8,6 +8,8 @@ class FilePath;
namespace utility
{
std::vector<FilePath> partitionFilePathsBySize(std::vector<FilePath> filePaths, int partitionCount = 0);
std::vector<FilePath> getTopLevelPaths(const std::vector<FilePath>& paths);
std::vector<FilePath> getTopLevelPaths(const std::set<FilePath>& paths);