Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2afaf4401 | |||
| 8be07c47cb | |||
| 5b84a007f6 | |||
| f9ee60eeb8 |
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user