Commit e73bce08 authored by Bernd Schmidt's avatar Bernd Schmidt Committed by Albert Astals Cid
Browse files

Make the cache work

There were two problems here: the QDateTime comparisons didn't return
true for files with unchanged mtime.  Using the same conversion on both
sides of the comparison fixes that.  As a result, startup now becomes
much faster since we're not rebuilding the cache each time.  Since
the format of the date has changed on-disk, this should be backwards
compatible, causing a one-time rebuild.

That exposed another problem that I was half-observing already before,
which is that the PNG thumbnails weren't being restored properly.
Converting the raw data to base64 when saving fixes that as well.

(cherry picked from commit 6fc25040)
parent d617b2d7
......@@ -47,7 +47,7 @@ Palapeli::PuzzleComponent* Palapeli::CollectionStorageComponent::cast(Type type)
//try to serve metadata from cache
const QDateTime mtime = QFileInfo(file).lastModified();
m_groupMutex->lock();
if (m_group->readEntry("ModifyDateTime", QDateTime()) == mtime)
if (m_group->readEntry("ModifyDateTime", QString()) == mtime.toString())
{
//cache is up-to-date
Palapeli::PuzzleMetadata metadata;
......@@ -56,7 +56,8 @@ Palapeli::PuzzleComponent* Palapeli::CollectionStorageComponent::cast(Type type)
metadata.author = m_group->readEntry("Author", QString());
metadata.pieceCount = m_group->readEntry("PieceCount", 0);
metadata.modifyProtection = m_group->readEntry("ModifyProtection", false);
metadata.thumbnail.loadFromData(m_group->readEntry("Thumbnail", QByteArray()));
QByteArray ar = m_group->readEntry("Thumbnail", QByteArray());
metadata.thumbnail.loadFromData(QByteArray::fromBase64 (ar));
m_groupMutex->unlock();
return new Palapeli::MetadataComponent(metadata);
}
......@@ -81,8 +82,8 @@ Palapeli::PuzzleComponent* Palapeli::CollectionStorageComponent::cast(Type type)
m_group->writeEntry("Author", metadata.author);
m_group->writeEntry("PieceCount", metadata.pieceCount);
m_group->writeEntry("ModifyProtection", metadata.modifyProtection);
m_group->writeEntry("ModifyDateTime", mtime);
m_group->writeEntry("Thumbnail", buffer.data());
m_group->writeEntry("ModifyDateTime", mtime.toString());
m_group->writeEntry("Thumbnail", buffer.data().toBase64 ());
m_group->sync();
m_groupMutex->unlock();
return cMetadata;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment