Skip to content

Commit

Permalink
Rename variable for clarity
Browse files Browse the repository at this point in the history
The cache now persists more than just translations.
  • Loading branch information
Piccirello committed Nov 27, 2024
1 parent 15ea836 commit d93ee05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/webui/webapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void WebApplication::configure()
{
m_isAltUIUsed = isAltUIUsed;
m_rootFolder = rootFolder;
m_translatedFiles.clear();
m_cachedFiles.clear();
if (!m_isAltUIUsed)
LogMsg(tr("Using built-in WebUI."));
else
Expand All @@ -423,7 +423,7 @@ void WebApplication::configure()
if (m_currentLocale != newLocale)
{
m_currentLocale = newLocale;
m_translatedFiles.clear();
m_cachedFiles.clear();

m_translationFileLoaded = m_translator.load((m_rootFolder / Path(u"translations/webui_"_s) + newLocale).data());
if (m_translationFileLoaded)
Expand Down Expand Up @@ -539,8 +539,8 @@ void WebApplication::sendFile(const Path &path)
// find translated file in cache
if (!m_isAltUIUsed)
{
if (const auto it = m_translatedFiles.constFind(path);
(it != m_translatedFiles.constEnd()) && (lastModified <= it->lastModified))
if (const auto it = m_cachedFiles.constFind(path);
(it != m_cachedFiles.constEnd()) && (lastModified <= it->lastModified))
{
print(it->data, it->mimeType);
setHeader({Http::HEADER_CACHE_CONTROL, getCachingInterval(it->mimeType)});
Expand Down Expand Up @@ -589,7 +589,7 @@ void WebApplication::sendFile(const Path &path)
dataStr.replace(u"${LANGUAGE_OPTIONS}"_s, createLanguagesOptionsHtml());

data = dataStr.toUtf8();
m_translatedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file
m_cachedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file
}

print(data, mimeType.name());
Expand Down
4 changes: 2 additions & 2 deletions src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ class WebApplication final : public ApplicationComponent<QObject>
bool m_isAltUIUsed = false;
Path m_rootFolder;

struct TranslatedFile
struct CachedFile
{
QByteArray data;
QString mimeType;
QDateTime lastModified;
};
QHash<Path, TranslatedFile> m_translatedFiles;
QHash<Path, CachedFile> m_cachedFiles;
QString m_currentLocale;
QTranslator m_translator;
bool m_translationFileLoaded = false;
Expand Down

0 comments on commit d93ee05

Please sign in to comment.