Improve performance significantly. We store if (and if: why) a certain domain was blocked for any requesting client and can immediately reply similarly if the same client requests the same domain again. This reduces the O(N^3) problem (number of queries * number of domains * number of clients) to a O(N^2) problem (domains * clients). Note that this state of the code still lacks a possibility to reset when entries in the database have changed. For this, we still have to send either SIGHUP (drawback: clears the cache) or define a new signal for it.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-11-22 09:42:06 +01:00
parent 7fd801dbc2
commit faac7005d1
9 changed files with 347 additions and 119 deletions
+9 -2
View File
@@ -126,8 +126,8 @@ int findDomainID(const char *domainString)
domain->blockedcount = 0;
// Store domain name - no need to check for NULL here as it doesn't harm
domain->domainpos = addstr(domainString);
// RegEx needs to be evaluated for this new domain
domain->regexmatch = REGEX_UNKNOWN;
// Storage for individual client blocking status
domain->clientstatus = new_ucharvec(counters->clients);
// Increase counter by one
counters->domains++;
@@ -201,6 +201,13 @@ int findClientID(const char *clientIP, const bool count)
for(int i = 0; i < OVERTIME_SLOTS; i++)
client->overTime[i] = 0;
// Initialize client-specific domain data
for(int domainID = 0; domainID < counters->domains; domainID++)
{
domainsData *domain = getDomain(domainID, true);
domain->clientstatus->append(domain->clientstatus, UNKNOWN_BLOCKED);
}
// Allocate regex substructure
allocate_regex_client_enabled(client);