Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1dc136647a | |||
| 7bdbb40a5d | |||
| 380761988b | |||
| e51e4a4d8c | |||
| faf8aacd15 | |||
| 4955fa8793 |
@@ -133,7 +133,14 @@ public:
|
||||
*/
|
||||
auto at(qsizetype index) const -> T
|
||||
{
|
||||
return get(index);
|
||||
QMutexLocker dataLocker(&m_dataMutex);
|
||||
|
||||
if(index < 0 || index >= m_data.count())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return m_data.at(index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +151,7 @@ public:
|
||||
*/
|
||||
auto totalResults() -> qsizetype
|
||||
{
|
||||
return m_cacheController.count();
|
||||
return m_cacheController.totalCount();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,24 +264,6 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief get
|
||||
* Private thread-safe get operation. This is needed to preserve the constness
|
||||
* of the at function
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
auto get(qsizetype index) -> T
|
||||
{
|
||||
QMutexLocker dataLocker(&m_dataMutex);
|
||||
|
||||
if(index < 0 || index >= m_data.count())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return m_data.at(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief m_offset
|
||||
@@ -307,7 +296,7 @@ private:
|
||||
/**
|
||||
* @brief m_dataMutex
|
||||
*/
|
||||
QMutex m_dataMutex;
|
||||
mutable QMutex m_dataMutex;
|
||||
};
|
||||
|
||||
#endif // PAGINATOR_H
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <functional>
|
||||
#include "fetchresult.h"
|
||||
#include "komplex_global.h"
|
||||
#include "logging.h"
|
||||
|
||||
/**
|
||||
* @brief The SlidingCacheNotifier class
|
||||
@@ -84,7 +85,7 @@ public:
|
||||
* @return CacheObject* or nullptr
|
||||
*/
|
||||
[[nodiscard]]
|
||||
auto at(qsizetype index) -> T
|
||||
auto at(qsizetype index) const -> T
|
||||
{
|
||||
QMutexLocker cacheLocker(&m_cacheMutex);
|
||||
|
||||
@@ -117,7 +118,7 @@ public:
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]]
|
||||
auto chunk(qsizetype index, qsizetype count) -> QList<T>
|
||||
auto chunk(qsizetype index, qsizetype count) const -> QList<T>
|
||||
{
|
||||
QMutexLocker cacheLocker(&m_cacheMutex);
|
||||
|
||||
@@ -317,7 +318,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
setCount(result.total);
|
||||
setTotalCount(result.total);
|
||||
|
||||
if(result.data.isEmpty())
|
||||
{
|
||||
@@ -379,7 +380,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
setCount(result.total);
|
||||
setTotalCount(result.total);
|
||||
|
||||
while(!result.data.isEmpty() && !m_cache.isEmpty())
|
||||
{
|
||||
@@ -389,7 +390,7 @@ private:
|
||||
m_cache.push_front(std::move(object));
|
||||
}
|
||||
|
||||
if(!result.results.isEmpty())
|
||||
if(!result.data.isEmpty())
|
||||
{
|
||||
LOG_ERROR_X((result.count + m_cache.count()) > SLIDING_CACHE_WINDOW_SIZE,
|
||||
"SlidingCacheController::slideBackward",
|
||||
@@ -397,7 +398,11 @@ private:
|
||||
false
|
||||
);
|
||||
|
||||
m_cache.push_front(std::move(result.data));
|
||||
while(!result.data.isEmpty())
|
||||
{
|
||||
T object = result.data.takeLast();
|
||||
m_cache.push_front(std::move(object));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -443,7 +448,7 @@ private:
|
||||
/**
|
||||
* @brief m_cacheMutex
|
||||
*/
|
||||
QMutex m_cacheMutex;
|
||||
mutable QMutex m_cacheMutex;
|
||||
};
|
||||
|
||||
#endif // SLIDINGCACHECONTROLLER_H
|
||||
|
||||
@@ -50,6 +50,28 @@ struct KOMPLEX_EXPORT WallpaperCache
|
||||
QString currency;
|
||||
quint64 downloadCount = 0;
|
||||
qint8 type = -1;
|
||||
|
||||
auto operator == (const WallpaperCache &other) const -> bool
|
||||
{
|
||||
return (
|
||||
other.uri == uri &&
|
||||
other.name == name &&
|
||||
other.author == author &&
|
||||
other.authorId == authorId &&
|
||||
other.description == description &&
|
||||
other.thumbnail == thumbnail &&
|
||||
other.createdDate == createdDate &&
|
||||
other.price == price &&
|
||||
other.currency == currency &&
|
||||
other.downloadCount == downloadCount &&
|
||||
other.type == type
|
||||
);
|
||||
}
|
||||
|
||||
auto operator != (const WallpaperCache &other) const -> bool
|
||||
{
|
||||
return !(other == *this);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(WallpaperCache)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user