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,19 +229,16 @@ 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)) { if (rule.matches(im)) {
for (auto &rule : rules) { printf("found matching profile %s\n",
if (rule.matches(im)) { rule.profilepath.c_str());
printf("found matching profile %s\n", const PartialProfile *p =
rule.profilepath.c_str()); profileStore.getProfile(rule.profilepath);
const PartialProfile *p = if (p != nullptr) {
profileStore.getProfile(rule.profilepath); p->applyTo(ret->pparams);
if (p != nullptr) { } else {
p->applyTo(ret->pparams); printf("ERROR loading matching profile\n");
} else {
printf("ERROR loading matching profile\n");
}
} }
} }
} }

View File

@@ -308,11 +308,8 @@ DynamicProfilePanel::DynamicProfilePanel():
show_all_children(); show_all_children();
std::vector<DynamicProfileRule> rules; for (auto &r : profileStore.getDynamicProfileRules()) {
if (loadDynamicProfileRules(rules)) { add_rule(r);
for (auto &r : rules) {
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);