mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Writing cache files async
This commit is contained in:
parent
d6627b531e
commit
7d842e6cf7
2 changed files with 12 additions and 12 deletions
|
@ -47,18 +47,20 @@ QString NetworkData::getHash()
|
||||||
return this->hash_;
|
return this->hash_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkData::writeToCache(const QByteArray &bytes)
|
void writeToCache(const std::shared_ptr<NetworkData> &data,
|
||||||
|
const QByteArray &bytes)
|
||||||
{
|
{
|
||||||
if (this->useQuickLoadCache_)
|
if (data->useQuickLoadCache_)
|
||||||
{
|
{
|
||||||
QFile cachedFile(getPaths()->cacheDirectory() + "/" + this->getHash());
|
QtConcurrent::run([data, bytes] {
|
||||||
|
QFile cachedFile(getPaths()->cacheDirectory() + "/" +
|
||||||
|
data->getHash());
|
||||||
|
|
||||||
if (cachedFile.open(QIODevice::WriteOnly))
|
if (cachedFile.open(QIODevice::WriteOnly))
|
||||||
{
|
{
|
||||||
cachedFile.write(bytes);
|
cachedFile.write(bytes);
|
||||||
|
}
|
||||||
cachedFile.close();
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +136,7 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray bytes = reply->readAll();
|
QByteArray bytes = reply->readAll();
|
||||||
data->writeToCache(bytes);
|
writeToCache(data, bytes);
|
||||||
|
|
||||||
NetworkResult result(bytes);
|
NetworkResult result(bytes);
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,6 @@ struct NetworkData {
|
||||||
|
|
||||||
QString getHash();
|
QString getHash();
|
||||||
|
|
||||||
void writeToCache(const QByteArray &bytes);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString hash_;
|
QString hash_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue