monitor: accumulate mods during 30S before indexing

This commit is contained in:
dockes 2009-11-14 11:34:35 +00:00
parent 061aa959c6
commit 1406bca35b

View File

@ -294,7 +294,13 @@ bool startMonitor(RclConfig *conf, int opts)
LOGDEB(("start_monitoring: entering main loop\n")); LOGDEB(("start_monitoring: entering main loop\n"));
bool timedout; bool timedout;
time_t lastauxtime = time(0); time_t lastauxtime = time(0);
time_t lastixtime = lastauxtime;
bool didsomething = false; bool didsomething = false;
const int auxinterval = 60 *60;
const int ixinterval = 30;
list<string> modified;
list<string> deleted;
// Set a relatively short timeout for better monitoring of exit requests // Set a relatively short timeout for better monitoring of exit requests
while (rclEQ.wait(2, &timedout)) { while (rclEQ.wait(2, &timedout)) {
@ -310,9 +316,6 @@ bool startMonitor(RclConfig *conf, int opts)
break; break;
} }
list<string> modified;
list<string> deleted;
// Process event queue // Process event queue
while (!rclEQ.empty()) { while (!rclEQ.empty()) {
// Retrieve event // Retrieve event
@ -333,20 +336,30 @@ bool startMonitor(RclConfig *conf, int opts)
// Unlock queue before processing lists // Unlock queue before processing lists
rclEQ.unlock(); rclEQ.unlock();
// Process // Process. We don't do this everytime but let the lists accumulate
// a little, this saves processing.
time_t now = time(0);
if (now - lastixtime > ixinterval) {
lastixtime = now;
if (!modified.empty()) { if (!modified.empty()) {
modified.sort();
modified.unique();
if (!indexfiles(conf, modified)) if (!indexfiles(conf, modified))
break; break;
modified.clear();
didsomething = true; didsomething = true;
} }
if (!deleted.empty()) { if (!deleted.empty()) {
deleted.sort();
deleted.unique();
if (!purgefiles(conf, deleted)) if (!purgefiles(conf, deleted))
break; break;
deleted.clear();
didsomething = true; didsomething = true;
} }
}
// Recreate the auxiliary dbs every hour at most. // Recreate the auxiliary dbs every hour at most.
const int auxinterval = 60 *60;
if (didsomething && time(0) - lastauxtime > auxinterval) { if (didsomething && time(0) - lastauxtime > auxinterval) {
lastauxtime = time(0); lastauxtime = time(0);
didsomething = false; didsomething = false;