Browse Source

Cache and reuse detected MIME type

adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
230949ee3b
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 11
      src/webui/webapplication.cpp
  2. 1
      src/webui/webapplication.h

11
src/webui/webapplication.cpp

@ -368,11 +368,10 @@ void WebApplication::sendFile(const QString &path)
const QDateTime lastModified {QFileInfo(path).lastModified()}; const QDateTime lastModified {QFileInfo(path).lastModified()};
// find translated file in cache // find translated file in cache
auto it = m_translatedFiles.constFind(path); const auto it = m_translatedFiles.constFind(path);
if ((it != m_translatedFiles.constEnd()) && (lastModified <= (*it).lastModified)) { if ((it != m_translatedFiles.constEnd()) && (lastModified <= it->lastModified)) {
const QString mimeName {QMimeDatabase().mimeTypeForFileNameAndData(path, (*it).data).name()}; print(it->data, it->mimeType);
print((*it).data, mimeName); header(Http::HEADER_CACHE_CONTROL, getCachingInterval(it->mimeType));
header(Http::HEADER_CACHE_CONTROL, getCachingInterval(mimeName));
return; return;
} }
@ -400,7 +399,7 @@ void WebApplication::sendFile(const QString &path)
translateDocument(dataStr); translateDocument(dataStr);
data = dataStr.toUtf8(); 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()); print(data, mimeType.name());

1
src/webui/webapplication.h

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

Loading…
Cancel
Save