Compare commits

..

4 Commits

Author SHA1 Message Date
Digital Artifex a2afaf4401 Added private get function to preserve constness of at() 2026-06-08 22:42:49 -04:00
Digital Artifex 8be07c47cb Added individual paginators for API endpoints 2026-06-08 22:15:17 -04:00
Digital Artifex 5b84a007f6 Added generic WallpaperPaginator class 2026-06-08 22:00:13 -04:00
Digital Artifex f9ee60eeb8 Added reset method and updated comments 2026-06-08 21:52:09 -04:00
3 changed files with 28 additions and 44 deletions
+21 -10
View File
@@ -133,14 +133,7 @@ public:
*/ */
auto at(qsizetype index) const -> T auto at(qsizetype index) const -> T
{ {
QMutexLocker dataLocker(&m_dataMutex); return get(index);
if(index < 0 || index >= m_data.count())
{
return {};
}
return m_data.at(index);
} }
/** /**
@@ -151,7 +144,7 @@ public:
*/ */
auto totalResults() -> qsizetype auto totalResults() -> qsizetype
{ {
return m_cacheController.totalCount(); return m_cacheController.count();
} }
/** /**
@@ -264,6 +257,24 @@ protected:
} }
private: 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 * @brief m_offset
@@ -296,7 +307,7 @@ private:
/** /**
* @brief m_dataMutex * @brief m_dataMutex
*/ */
mutable QMutex m_dataMutex; QMutex m_dataMutex;
}; };
#endif // PAGINATOR_H #endif // PAGINATOR_H
@@ -27,7 +27,6 @@
#include <functional> #include <functional>
#include "fetchresult.h" #include "fetchresult.h"
#include "komplex_global.h" #include "komplex_global.h"
#include "logging.h"
/** /**
* @brief The SlidingCacheNotifier class * @brief The SlidingCacheNotifier class
@@ -85,7 +84,7 @@ public:
* @return CacheObject* or nullptr * @return CacheObject* or nullptr
*/ */
[[nodiscard]] [[nodiscard]]
auto at(qsizetype index) const -> T auto at(qsizetype index) -> T
{ {
QMutexLocker cacheLocker(&m_cacheMutex); QMutexLocker cacheLocker(&m_cacheMutex);
@@ -118,7 +117,7 @@ public:
* @return * @return
*/ */
[[nodiscard]] [[nodiscard]]
auto chunk(qsizetype index, qsizetype count) const -> QList<T> auto chunk(qsizetype index, qsizetype count) -> QList<T>
{ {
QMutexLocker cacheLocker(&m_cacheMutex); QMutexLocker cacheLocker(&m_cacheMutex);
@@ -318,7 +317,7 @@ private:
return false; return false;
} }
setTotalCount(result.total); setCount(result.total);
if(result.data.isEmpty()) if(result.data.isEmpty())
{ {
@@ -380,7 +379,7 @@ private:
return false; return false;
} }
setTotalCount(result.total); setCount(result.total);
while(!result.data.isEmpty() && !m_cache.isEmpty()) while(!result.data.isEmpty() && !m_cache.isEmpty())
{ {
@@ -390,7 +389,7 @@ private:
m_cache.push_front(std::move(object)); m_cache.push_front(std::move(object));
} }
if(!result.data.isEmpty()) if(!result.results.isEmpty())
{ {
LOG_ERROR_X((result.count + m_cache.count()) > SLIDING_CACHE_WINDOW_SIZE, LOG_ERROR_X((result.count + m_cache.count()) > SLIDING_CACHE_WINDOW_SIZE,
"SlidingCacheController::slideBackward", "SlidingCacheController::slideBackward",
@@ -398,11 +397,7 @@ private:
false false
); );
while(!result.data.isEmpty()) m_cache.push_front(std::move(result.data));
{
T object = result.data.takeLast();
m_cache.push_front(std::move(object));
}
} }
return true; return true;
@@ -448,7 +443,7 @@ private:
/** /**
* @brief m_cacheMutex * @brief m_cacheMutex
*/ */
mutable QMutex m_cacheMutex; QMutex m_cacheMutex;
}; };
#endif // SLIDINGCACHECONTROLLER_H #endif // SLIDINGCACHECONTROLLER_H
-22
View File
@@ -50,28 +50,6 @@ struct KOMPLEX_EXPORT WallpaperCache
QString currency; QString currency;
quint64 downloadCount = 0; quint64 downloadCount = 0;
qint8 type = -1; 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) Q_DECLARE_METATYPE(WallpaperCache)