From e621a835fd94364c2670cc65a4ef7c916e45a656 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 2 Sep 2019 15:55:28 +0200 Subject: [PATCH] logic: use caching to speed up preparing gradle and maven projects for indexing --- .../project/SourceGroupJavaGradle.cpp | 38 +++++++++------- src/lib_java/project/SourceGroupJavaGradle.h | 3 ++ src/lib_java/project/SourceGroupJavaMaven.cpp | 44 +++++++++++-------- src/lib_java/project/SourceGroupJavaMaven.h | 3 ++ 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/lib_java/project/SourceGroupJavaGradle.cpp b/src/lib_java/project/SourceGroupJavaGradle.cpp index ce283479..29a2c16a 100644 --- a/src/lib_java/project/SourceGroupJavaGradle.cpp +++ b/src/lib_java/project/SourceGroupJavaGradle.cpp @@ -12,6 +12,7 @@ SourceGroupJavaGradle::SourceGroupJavaGradle(std::shared_ptr settings) : m_settings(settings) + , m_allSourcePathsCache(std::bind(&SourceGroupJavaGradle::doGetAllSourcePaths, this)) { } @@ -32,22 +33,7 @@ bool SourceGroupJavaGradle::prepareIndexing() std::vector SourceGroupJavaGradle::getAllSourcePaths() const { - std::vector sourcePaths; - if (m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists()) - { - std::shared_ptr dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP); - dialogView->showUnknownProgressDialog(L"Preparing Project", L"Gradle\nFetching Source Directories"); - - const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory(); - sourcePaths = utility::gradleGetAllSourceDirectories(projectRootPath, m_settings->getShouldIndexGradleTests()); - - dialogView->hideUnknownProgressDialog(); - } - else - { - LOG_INFO("Could not find any source paths because Gradle project path does not exist."); - } - return sourcePaths; + return m_allSourcePathsCache.getValue(); } std::vector SourceGroupJavaGradle::doGetClassPath() const @@ -107,3 +93,23 @@ bool SourceGroupJavaGradle::prepareGradleData() return true; } + +std::vector SourceGroupJavaGradle::doGetAllSourcePaths() const +{ + std::vector sourcePaths; + if (m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists()) + { + std::shared_ptr dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP); + dialogView->showUnknownProgressDialog(L"Preparing Project", L"Gradle\nFetching Source Directories"); + + const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory(); + sourcePaths = utility::gradleGetAllSourceDirectories(projectRootPath, m_settings->getShouldIndexGradleTests()); + + dialogView->hideUnknownProgressDialog(); + } + else + { + LOG_INFO("Could not find any source paths because Gradle project path does not exist."); + } + return sourcePaths; +} diff --git a/src/lib_java/project/SourceGroupJavaGradle.h b/src/lib_java/project/SourceGroupJavaGradle.h index b667c033..bace2eef 100644 --- a/src/lib_java/project/SourceGroupJavaGradle.h +++ b/src/lib_java/project/SourceGroupJavaGradle.h @@ -4,6 +4,7 @@ #include #include +#include "SingleValueCache.h" #include "SourceGroupJava.h" class SourceGroupSettingsJavaGradle; @@ -21,8 +22,10 @@ private: std::shared_ptr getSourceGroupSettings() override; std::shared_ptr getSourceGroupSettings() const override; bool prepareGradleData(); + std::vector doGetAllSourcePaths() const; std::shared_ptr m_settings; + mutable SingleValueCache> m_allSourcePathsCache; }; #endif // SOURCE_GROUP_JAVA_GRADLE_H diff --git a/src/lib_java/project/SourceGroupJavaMaven.cpp b/src/lib_java/project/SourceGroupJavaMaven.cpp index b5dfdfba..4a3f3900 100644 --- a/src/lib_java/project/SourceGroupJavaMaven.cpp +++ b/src/lib_java/project/SourceGroupJavaMaven.cpp @@ -14,6 +14,7 @@ SourceGroupJavaMaven::SourceGroupJavaMaven(std::shared_ptr settings) : m_settings(settings) + , m_allSourcePathsCache(std::bind(&SourceGroupJavaMaven::doGetAllSourcePaths, this)) { } @@ -34,25 +35,7 @@ bool SourceGroupJavaMaven::prepareIndexing() std::vector SourceGroupJavaMaven::getAllSourcePaths() const { - std::vector sourcePaths; - if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists()) - { - std::shared_ptr dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP); - dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nFetching Source Directories"); - - const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath()); - const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory(); - - sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom( - mavenPath, - projectRootPath, - m_settings->getMavenDependenciesDirectoryPath(), - m_settings->getShouldIndexMavenTests() - ); - - dialogView->hideUnknownProgressDialog(); - } - return sourcePaths; + return m_allSourcePathsCache.getValue(); } std::vector SourceGroupJavaMaven::doGetClassPath() const @@ -120,3 +103,26 @@ bool SourceGroupJavaMaven::prepareMavenData() return true; } + +std::vector SourceGroupJavaMaven::doGetAllSourcePaths() const +{ + std::vector sourcePaths; + if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists()) + { + std::shared_ptr dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP); + dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nFetching Source Directories"); + + const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath()); + const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory(); + + sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom( + mavenPath, + projectRootPath, + m_settings->getMavenDependenciesDirectoryPath(), + m_settings->getShouldIndexMavenTests() + ); + + dialogView->hideUnknownProgressDialog(); + } + return sourcePaths; +} diff --git a/src/lib_java/project/SourceGroupJavaMaven.h b/src/lib_java/project/SourceGroupJavaMaven.h index 8fdeba55..54c35ae8 100644 --- a/src/lib_java/project/SourceGroupJavaMaven.h +++ b/src/lib_java/project/SourceGroupJavaMaven.h @@ -4,6 +4,7 @@ #include #include +#include "SingleValueCache.h" #include "SourceGroupJava.h" class SourceGroupSettingsJavaMaven; @@ -20,8 +21,10 @@ private: std::shared_ptr getSourceGroupSettings() override; std::shared_ptr getSourceGroupSettings() const override; bool prepareMavenData(); + std::vector doGetAllSourcePaths() const; std::shared_ptr m_settings; + mutable SingleValueCache> m_allSourcePathsCache; }; #endif // SOURCE_GROUP_JAVA_MAVEN_H