Browse Source

Merge pull request #11075 from Chocobo1/cache

Cache and reuse detected MIME type
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
d639c16f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/webui/webapplication.cpp
  2. 3
      src/webui/webapplication.h

13
src/webui/webapplication.cpp

@ -191,7 +191,7 @@ void WebApplication::sendWebUIFile() @@ -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_]*)\\]");
@ -368,11 +368,10 @@ void WebApplication::sendFile(const QString &path) @@ -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) @@ -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());

3
src/webui/webapplication.h

@ -105,7 +105,7 @@ private: @@ -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;
@ -136,6 +136,7 @@ private: @@ -136,6 +136,7 @@ private:
struct TranslatedFile
{
QByteArray data;
QString mimeType;
QDateTime lastModified;
};
QHash<QString, TranslatedFile> m_translatedFiles;

Loading…
Cancel
Save