Compare commits

..

6 Commits

Author SHA1 Message Date
Digital Artifex 1dc136647a Added comparison operators 2026-06-09 00:25:43 -04:00
Digital Artifex 7bdbb40a5d Added individual paginators for API endpoints 2026-06-09 00:25:17 -04:00
Digital Artifex 380761988b Moved generic functionality to WallpaperPaginator 2026-06-09 00:24:40 -04:00
Digital Artifex e51e4a4d8c Updated mutex and comments 2026-06-09 00:23:11 -04:00
Digital Artifex faf8aacd15 Added generic WallpaperPaginator class 2026-06-09 00:22:16 -04:00
Digital Artifex 4955fa8793 Updated mutex and comments 2026-06-09 00:21:21 -04:00
3 changed files with 44 additions and 28 deletions
+10 -21
View File
@@ -133,7 +133,14 @@ public:
*/ */
auto at(qsizetype index) const -> T 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 auto totalResults() -> qsizetype
{ {
return m_cacheController.count(); return m_cacheController.totalCount();
} }
/** /**
@@ -257,24 +264,6 @@ 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
@@ -307,7 +296,7 @@ private:
/** /**
* @brief m_dataMutex * @brief m_dataMutex
*/ */
QMutex m_dataMutex; mutable QMutex m_dataMutex;
}; };
#endif // PAGINATOR_H #endif // PAGINATOR_H
@@ -27,6 +27,7 @@
#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
@@ -84,7 +85,7 @@ public:
* @return CacheObject* or nullptr * @return CacheObject* or nullptr
*/ */
[[nodiscard]] [[nodiscard]]
auto at(qsizetype index) -> T auto at(qsizetype index) const -> T
{ {
QMutexLocker cacheLocker(&m_cacheMutex); QMutexLocker cacheLocker(&m_cacheMutex);
@@ -117,7 +118,7 @@ public:
* @return * @return
*/ */
[[nodiscard]] [[nodiscard]]
auto chunk(qsizetype index, qsizetype count) -> QList<T> auto chunk(qsizetype index, qsizetype count) const -> QList<T>
{ {
QMutexLocker cacheLocker(&m_cacheMutex); QMutexLocker cacheLocker(&m_cacheMutex);
@@ -317,7 +318,7 @@ private:
return false; return false;
} }
setCount(result.total); setTotalCount(result.total);
if(result.data.isEmpty()) if(result.data.isEmpty())
{ {
@@ -379,7 +380,7 @@ private:
return false; return false;
} }
setCount(result.total); setTotalCount(result.total);
while(!result.data.isEmpty() && !m_cache.isEmpty()) while(!result.data.isEmpty() && !m_cache.isEmpty())
{ {
@@ -389,7 +390,7 @@ private:
m_cache.push_front(std::move(object)); 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, LOG_ERROR_X((result.count + m_cache.count()) > SLIDING_CACHE_WINDOW_SIZE,
"SlidingCacheController::slideBackward", "SlidingCacheController::slideBackward",
@@ -397,7 +398,11 @@ private:
false 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; return true;
@@ -443,7 +448,7 @@ private:
/** /**
* @brief m_cacheMutex * @brief m_cacheMutex
*/ */
QMutex m_cacheMutex; mutable QMutex m_cacheMutex;
}; };
#endif // SLIDINGCACHECONTROLLER_H #endif // SLIDINGCACHECONTROLLER_H
+22
View File
@@ -50,6 +50,28 @@ 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)