The elements cache now expects the element mtime to be equal to the one stored in the cache entry.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1841 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-05-14 19:23:30 +00:00
parent 191fbab78e
commit 81c0532fc2
2 changed files with 15 additions and 12 deletions

View File

@@ -35,8 +35,8 @@ ElementsCollectionCache::ElementsCollectionCache(const QString &database_path, Q
select_pixmap_ = new QSqlQuery(cache_db_); select_pixmap_ = new QSqlQuery(cache_db_);
insert_name_ = new QSqlQuery(cache_db_); insert_name_ = new QSqlQuery(cache_db_);
insert_pixmap_ = new QSqlQuery(cache_db_); insert_pixmap_ = new QSqlQuery(cache_db_);
select_name_ -> prepare("SELECT name FROM names WHERE path = :path AND locale = :locale AND mtime > :file_mtime"); select_name_ -> prepare("SELECT name FROM names WHERE path = :path AND locale = :locale AND mtime = :file_mtime");
select_pixmap_ -> prepare("SELECT pixmap FROM pixmaps WHERE path = :path AND mtime > :file_mtime"); select_pixmap_ -> prepare("SELECT pixmap FROM pixmaps WHERE path = :path AND mtime = :file_mtime");
insert_name_ -> prepare("REPLACE INTO names (path, locale, mtime, name) VALUES (:path, :locale, :mtime, :name)"); insert_name_ -> prepare("REPLACE INTO names (path, locale, mtime, name) VALUES (:path, :locale, :mtime, :name)");
insert_pixmap_ -> prepare("REPLACE INTO pixmaps (path, mtime, pixmap) VALUES (:path, :mtime, :pixmap)"); insert_pixmap_ -> prepare("REPLACE INTO pixmaps (path, mtime, pixmap) VALUES (:path, :mtime, :pixmap)");
} }
@@ -134,14 +134,15 @@ bool ElementsCollectionCache::fetchElement(ElementDefinition *element) {
return(fetchData(element -> location())); return(fetchData(element -> location()));
} else { } else {
QString element_path = element -> location().toString(); QString element_path = element -> location().toString();
bool got_name = fetchNameFromCache(element_path, element -> modificationTime()); QDateTime mtime = element -> modificationTime();
bool got_pixmap = fetchPixmapFromCache(element_path, element -> modificationTime()); bool got_name = fetchNameFromCache(element_path, mtime);
bool got_pixmap = fetchPixmapFromCache(element_path, mtime);
if (got_name && got_pixmap) { if (got_name && got_pixmap) {
return(true); return(true);
} }
if (fetchData(element -> location())) { if (fetchData(element -> location())) {
cacheName(element_path); cacheName(element_path, mtime);
cachePixmap(element_path); cachePixmap(element_path, mtime);
} }
return(true); return(true);
} }
@@ -235,13 +236,14 @@ bool ElementsCollectionCache::fetchPixmapFromCache(const QString &path, const QD
Cache the current (i.e. last retrieved) name. The cache entry will use Cache the current (i.e. last retrieved) name. The cache entry will use
the current date and time and the locale set via setLocale(). the current date and time and the locale set via setLocale().
@param path Element path (as obtained using ElementsLocation::toString()) @param path Element path (as obtained using ElementsLocation::toString())
@param mtime Modification time associated with the cache entry -- defaults to current datetime
@return True if the caching succeeded, false otherwise. @return True if the caching succeeded, false otherwise.
@see name() @see name()
*/ */
bool ElementsCollectionCache::cacheName(const QString &path) { bool ElementsCollectionCache::cacheName(const QString &path, const QDateTime &mtime) {
insert_name_ -> bindValue(":path", path); insert_name_ -> bindValue(":path", path);
insert_name_ -> bindValue(":locale", locale_); insert_name_ -> bindValue(":locale", locale_);
insert_name_ -> bindValue(":mtime", QVariant(QDateTime::currentDateTime())); insert_name_ -> bindValue(":mtime", QVariant(mtime));
insert_name_ -> bindValue(":name", current_name_); insert_name_ -> bindValue(":name", current_name_);
if (!insert_name_ -> exec()) { if (!insert_name_ -> exec()) {
qDebug() << cache_db_.lastError(); qDebug() << cache_db_.lastError();
@@ -254,16 +256,17 @@ bool ElementsCollectionCache::cacheName(const QString &path) {
Cache the current (i.e. last retrieved) pixmap. The cache entry will use Cache the current (i.e. last retrieved) pixmap. The cache entry will use
the current date and time. the current date and time.
@param path Element path (as obtained using ElementsLocation::toString()) @param path Element path (as obtained using ElementsLocation::toString())
@param mtime Modification time associated with the cache entry -- defaults to current datetime
@return True if the caching succeeded, false otherwise. @return True if the caching succeeded, false otherwise.
@see pixmap() @see pixmap()
*/ */
bool ElementsCollectionCache::cachePixmap(const QString &path) { bool ElementsCollectionCache::cachePixmap(const QString &path, const QDateTime &mtime) {
QByteArray ba; QByteArray ba;
QBuffer buffer(&ba); QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
current_pixmap_.save(&buffer, qPrintable(pixmap_storage_format_)); current_pixmap_.save(&buffer, qPrintable(pixmap_storage_format_));
insert_pixmap_ -> bindValue(":path", path); insert_pixmap_ -> bindValue(":path", path);
insert_pixmap_ -> bindValue(":mtime", QVariant(QDateTime::currentDateTime())); insert_pixmap_ -> bindValue(":mtime", QVariant(mtime));
insert_pixmap_ -> bindValue(":pixmap", QVariant(ba)); insert_pixmap_ -> bindValue(":pixmap", QVariant(ba));
if (!insert_pixmap_->exec()) { if (!insert_pixmap_->exec()) {
qDebug() << cache_db_.lastError(); qDebug() << cache_db_.lastError();

View File

@@ -49,8 +49,8 @@ class ElementsCollectionCache : public QObject {
bool fetchData(const ElementsLocation &); bool fetchData(const ElementsLocation &);
bool fetchNameFromCache(const QString &, const QDateTime &); bool fetchNameFromCache(const QString &, const QDateTime &);
bool fetchPixmapFromCache(const QString &, const QDateTime &); bool fetchPixmapFromCache(const QString &, const QDateTime &);
bool cacheName(const QString &); bool cacheName(const QString &, const QDateTime & = QDateTime::currentDateTime());
bool cachePixmap(const QString &); bool cachePixmap(const QString &, const QDateTime & = QDateTime::currentDateTime());
// attributes // attributes
private: private: