Updated mutex and comments

This commit is contained in:
Digital Artifex
2026-06-09 00:23:11 -04:00
parent 25c27d70e8
commit be263c934a
@@ -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