Cache DynamicProfileRuleS in the profileStore for reduced I/O

This commit is contained in:
Alberto Griggio
2017-03-04 14:16:26 +01:00
parent bc5a6fc7c3
commit dd4fd82582
4 changed files with 26 additions and 20 deletions

View File

@@ -229,9 +229,7 @@ bool storeDynamicProfileRules(const std::vector<DynamicProfileRule> &rules)
PartialProfile *loadDynamicProfile(const ImageMetaData *im) PartialProfile *loadDynamicProfile(const ImageMetaData *im)
{ {
PartialProfile *ret = new PartialProfile(true, true); PartialProfile *ret = new PartialProfile(true, true);
std::vector<DynamicProfileRule> rules; for (auto &rule : profileStore.getDynamicProfileRules()) {
if (loadDynamicProfileRules(rules)) {
for (auto &rule : rules) {
if (rule.matches(im)) { if (rule.matches(im)) {
printf("found matching profile %s\n", printf("found matching profile %s\n",
rule.profilepath.c_str()); rule.profilepath.c_str());
@@ -244,6 +242,5 @@ PartialProfile *loadDynamicProfile(const ImageMetaData *im)
} }
} }
} }
}
return ret; return ret;
} }

View File

@@ -308,12 +308,9 @@ DynamicProfilePanel::DynamicProfilePanel():
show_all_children(); show_all_children();
std::vector<DynamicProfileRule> rules; for (auto &r : profileStore.getDynamicProfileRules()) {
if (loadDynamicProfileRules(rules)) {
for (auto &r : rules) {
add_rule(r); add_rule(r);
} }
}
} }
@@ -514,13 +511,15 @@ void DynamicProfilePanel::on_button_edit()
void DynamicProfilePanel::save() void DynamicProfilePanel::save()
{ {
std::vector<DynamicProfileRule> rules; auto &rules = profileStore.getDynamicProfileRules();
rules.clear();
int serial = 1; int serial = 1;
for (auto row : treemodel_->children()) { for (auto row : treemodel_->children()) {
rules.emplace_back(to_rule(row, serial++)); rules.emplace_back(to_rule(row, serial++));
} }
if (!storeDynamicProfileRules(rules)) { if (!storeDynamicProfileRules(rules)) {
printf("Error in saving dynamic profile rules\n"); printf("Error in saving dynamic profile rules\n");
rules.clear();
} else { } else {
printf("Saved %d dynamic profile rules\n", int(rules.size())); printf("Saved %d dynamic profile rules\n", int(rules.size()));
} }

View File

@@ -42,6 +42,7 @@ bool ProfileStore::init ()
storeState = STORESTATE_BEINGINITIALIZED; storeState = STORESTATE_BEINGINITIALIZED;
parseMutex = new MyMutex(); parseMutex = new MyMutex();
_parseProfiles (); _parseProfiles ();
loadDynamicProfileRules(dynamicRules);
storeState = STORESTATE_INITIALIZED; storeState = STORESTATE_INITIALIZED;
} }

View File

@@ -29,6 +29,7 @@
#include "threadutils.h" #include "threadutils.h"
#include "paramsedited.h" #include "paramsedited.h"
#include "guiutils.h" #include "guiutils.h"
#include "dynamicprofile.h"
/** @brief This will implement callback functions for the ProfileStore /** @brief This will implement callback functions for the ProfileStore
@@ -161,6 +162,9 @@ private:
/** List of the client of this store */ /** List of the client of this store */
std::list<ProfileStoreListener*> listeners; std::list<ProfileStoreListener*> listeners;
/** cache for dynamic profile rules */
std::vector<DynamicProfileRule> dynamicRules;
/** @brief Method to recursively parse a profile folder with a level depth arbitrarily limited to 3 /** @brief Method to recursively parse a profile folder with a level depth arbitrarily limited to 3
* *
* @param realPath current full path of the scanned directory ; e.g.: ~/MyProfiles/ * @param realPath current full path of the scanned directory ; e.g.: ~/MyProfiles/
@@ -204,6 +208,11 @@ public:
return internalDynamicEntry; return internalDynamicEntry;
} }
std::vector<DynamicProfileRule> &getDynamicProfileRules()
{
return dynamicRules;
}
void addListener(ProfileStoreListener *listener); void addListener(ProfileStoreListener *listener);
void removeListener(ProfileStoreListener *listener); void removeListener(ProfileStoreListener *listener);