summaryrefslogtreecommitdiffstats
path: root/common/modelresult.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-23 15:45:19 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-23 15:45:19 +0100
commited4eae09dc7a3e5e3053a2544ef93791780204a1 (patch)
tree56e27a24073ab6ff6a3cba2d230466ebe7dcf36e /common/modelresult.cpp
parent87d70a4c3c52a9b6bb5c905bf02ec526f01f859f (diff)
downloadsink-ed4eae09dc7a3e5e3053a2544ef93791780204a1.tar.gz
sink-ed4eae09dc7a3e5e3053a2544ef93791780204a1.zip
Avoid fetching again if a fetch is already in progress.
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r--common/modelresult.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp
index 6695484..b738a05 100644
--- a/common/modelresult.cpp
+++ b/common/modelresult.cpp
@@ -24,8 +24,6 @@
24 24
25#include "log.h" 25#include "log.h"
26 26
27SINK_DEBUG_AREA("modelresult")
28
29static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type) 27static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type)
30{ 28{
31 // Q_ASSERT(!type.resourceInstanceIdentifier().isEmpty()); 29 // Q_ASSERT(!type.resourceInstanceIdentifier().isEmpty());
@@ -121,7 +119,7 @@ QModelIndex ModelResult<T, Ptr>::index(int row, int column, const QModelIndex &p
121 const auto childId = list.at(row); 119 const auto childId = list.at(row);
122 return createIndex(row, column, childId); 120 return createIndex(row, column, childId);
123 } 121 }
124 SinkWarning() << "Index not available " << row << column << parent; 122 SinkWarningCtx(mLogCtx) << "Index not available " << row << column << parent;
125 Q_ASSERT(false); 123 Q_ASSERT(false);
126 return QModelIndex(); 124 return QModelIndex();
127} 125}
@@ -191,7 +189,7 @@ void ModelResult<T, Ptr>::add(const Ptr &value)
191 return; 189 return;
192 } 190 }
193 if (mEntities.contains(childId)) { 191 if (mEntities.contains(childId)) {
194 SinkWarning() << "Entity already in model: " << value->identifier(); 192 SinkWarningCtx(mLogCtx) << "Entity already in model: " << value->identifier();
195 return; 193 return;
196 } 194 }
197 auto parent = createIndexFromId(id); 195 auto parent = createIndexFromId(id);
@@ -234,6 +232,11 @@ void ModelResult<T, Ptr>::fetchEntities(const QModelIndex &parent)
234{ 232{
235 Q_ASSERT(QThread::currentThread() == this->thread()); 233 Q_ASSERT(QThread::currentThread() == this->thread());
236 const auto id = getIdentifier(parent); 234 const auto id = getIdentifier(parent);
235 //There is already a fetch in progress, don't fetch again.
236 if (mEntityChildrenFetched.contains(id) && !mEntityChildrenFetchComplete.contains(id)) {
237 SinkTraceCtx(mLogCtx) << "A fetch is already in progress: " << parent;
238 return;
239 }
237 mEntityChildrenFetchComplete.remove(id); 240 mEntityChildrenFetchComplete.remove(id);
238 mEntityChildrenFetched.insert(id); 241 mEntityChildrenFetched.insert(id);
239 SinkTraceCtx(mLogCtx) << "Loading child entities of parent " << id; 242 SinkTraceCtx(mLogCtx) << "Loading child entities of parent " << id;
@@ -273,7 +276,7 @@ void ModelResult<T, Ptr>::setEmitter(const typename Sink::ResultEmitter<Ptr>::Pt
273 }); 276 });
274 }); 277 });
275 emitter->onInitialResultSetComplete([this](const Ptr &parent, bool fetchedAll) { 278 emitter->onInitialResultSetComplete([this](const Ptr &parent, bool fetchedAll) {
276 SinkTraceCtx(mLogCtx) << "Initial result set complete"; 279 SinkTraceCtx(mLogCtx) << "Initial result set complete. Fetched all: " << fetchedAll;
277 const qint64 parentId = parent ? qHash(*parent) : 0; 280 const qint64 parentId = parent ? qHash(*parent) : 0;
278 const auto parentIndex = createIndexFromId(parentId); 281 const auto parentIndex = createIndexFromId(parentId);
279 mEntityChildrenFetchComplete.insert(parentId); 282 mEntityChildrenFetchComplete.insert(parentId);