From 7c688a4acc452de7afffbddc1c71ceea57c6007e Mon Sep 17 00:00:00 2001
From: Matthieu Gautier
Date: Mon, 21 Mar 2022 18:01:07 +0100
Subject: [PATCH 01/29] Move `getCacheLength` to a generic helper function
`getEnvVar`
---
src/server/internalServer.cpp | 18 +++---------------
src/tools/otherTools.h | 17 +++++++++++++++++
2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp
index 0290d79a7..1ed43db94 100644
--- a/src/server/internalServer.cpp
+++ b/src/server/internalServer.cpp
@@ -95,18 +95,6 @@ inline std::string normalizeRootUrl(std::string rootUrl)
return rootUrl.empty() ? rootUrl : "/" + rootUrl;
}
-// Returns the value of env var `name` if found, otherwise returns defaultVal
-unsigned int getCacheLength(const char* name, unsigned int defaultVal) {
- try {
- const char* envString = std::getenv(name);
- if (envString == nullptr) {
- throw std::runtime_error("Environment variable not set");
- }
- return extractFromString(envString);
- } catch (...) {}
-
- return defaultVal;
-}
} // unnamed namespace
SearchInfo::SearchInfo(const std::string& pattern)
@@ -194,9 +182,9 @@ InternalServer::InternalServer(Library* library,
mp_daemon(nullptr),
mp_library(library),
mp_nameMapper(nameMapper ? nameMapper : &defaultNameMapper),
- searcherCache(getCacheLength("SEARCHER_CACHE_SIZE", std::max((unsigned int) (mp_library->getBookCount(true, true)*0.1), 1U))),
- searchCache(getCacheLength("SEARCH_CACHE_SIZE", DEFAULT_CACHE_SIZE)),
- suggestionSearcherCache(getCacheLength("SUGGESTION_SEARCHER_CACHE_SIZE", std::max((unsigned int) (mp_library->getBookCount(true, true)*0.1), 1U)))
+ searcherCache(getEnvVar("SEARCHER_CACHE_SIZE", std::max((unsigned int) (mp_library->getBookCount(true, true)*0.1), 1U))),
+ searchCache(getEnvVar("SEARCH_CACHE_SIZE", DEFAULT_CACHE_SIZE)),
+ suggestionSearcherCache(getEnvVar("SUGGESTION_SEARCHER_CACHE_SIZE", std::max((unsigned int) (mp_library->getBookCount(true, true)*0.1), 1U)))
{}
bool InternalServer::start() {
diff --git a/src/tools/otherTools.h b/src/tools/otherTools.h
index b1297798e..c0920d7bf 100644
--- a/src/tools/otherTools.h
+++ b/src/tools/otherTools.h
@@ -23,9 +23,12 @@
#include
#include
#include
- The requested book doesn't exist.
+ No such book: non-existing-book
)" },
{ /* url */ "/ROOT/search?content=non-existing-book&pattern=a\"