From 230949ee3b665a4c93a637980a43de883b37bd54 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 14 Aug 2019 17:48:40 +0800 Subject: [PATCH 1/2] Cache and reuse detected MIME type --- src/webui/webapplication.cpp | 11 +++++------ src/webui/webapplication.h | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 709abd481..f8a581034 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -368,11 +368,10 @@ void WebApplication::sendFile(const QString &path) const QDateTime lastModified {QFileInfo(path).lastModified()}; // find translated file in cache - auto it = m_translatedFiles.constFind(path); - if ((it != m_translatedFiles.constEnd()) && (lastModified <= (*it).lastModified)) { - const QString mimeName {QMimeDatabase().mimeTypeForFileNameAndData(path, (*it).data).name()}; - print((*it).data, mimeName); - header(Http::HEADER_CACHE_CONTROL, getCachingInterval(mimeName)); + const auto it = m_translatedFiles.constFind(path); + if ((it != m_translatedFiles.constEnd()) && (lastModified <= it->lastModified)) { + print(it->data, it->mimeType); + header(Http::HEADER_CACHE_CONTROL, getCachingInterval(it->mimeType)); return; } @@ -400,7 +399,7 @@ void WebApplication::sendFile(const QString &path) translateDocument(dataStr); data = dataStr.toUtf8(); - m_translatedFiles[path] = {data, lastModified}; // caching translated file + m_translatedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file } print(data, mimeType.name()); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 435c5fcb1..b67682050 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -136,6 +136,7 @@ private: struct TranslatedFile { QByteArray data; + QString mimeType; QDateTime lastModified; }; QHash m_translatedFiles; From f907328bdcc561a73529c340b41112449761ea72 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 14 Aug 2019 20:27:06 +0800 Subject: [PATCH 2/2] Add const to class function --- src/webui/webapplication.cpp | 2 +- src/webui/webapplication.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index f8a581034..4ca16c11f 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -191,7 +191,7 @@ void WebApplication::sendWebUIFile() sendFile(localPath); } -void WebApplication::translateDocument(QString &data) +void WebApplication::translateDocument(QString &data) const { const QRegularExpression regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\]"); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index b67682050..43b74d80c 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -105,7 +105,7 @@ private: void sendFile(const QString &path); void sendWebUIFile(); - void translateDocument(QString &data); + void translateDocument(QString &data) const; // Session management QString generateSid() const;