diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-04-04 20:58:57 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-04-04 20:58:57 +0200 |
commit | f690c7dde14a6f9c5fbf04ed94170c7648591cb6 (patch) | |
tree | 6e63dac978af3864622d0a9f85dac07f24318930 /fetchtopicsaction.cpp | |
parent | 256e7837ce8cb30b0c0a8c73306abdffa80365a6 (diff) | |
download | tapasboard-f690c7dde14a6f9c5fbf04ed94170c7648591cb6.tar.gz tapasboard-f690c7dde14a6f9c5fbf04ed94170c7648591cb6.zip |
store post position in database, create invisible items for unfetched
Diffstat (limited to 'fetchtopicsaction.cpp')
-rw-r--r-- | fetchtopicsaction.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/fetchtopicsaction.cpp b/fetchtopicsaction.cpp index bc94965..13aebdd 100644 --- a/fetchtopicsaction.cpp +++ b/fetchtopicsaction.cpp @@ -63,8 +63,11 @@ void FetchTopicsAction::handleFinishedCall() db.transaction(); QSqlQuery query(db); - query.prepare("INSERT OR REPLACE INTO topics (forum_id, topic_id, topic_title, topic_author_id, topic_author_name, is_subscribed, is_closed, icon_url, last_reply_time, reply_number, new_post, last_update_time) " - "VALUES (:forum_id, :topic_id, :topic_title, :topic_author_id, :topic_author_name, :is_subscribed, :is_closed, :icon_url, :last_reply_time, :reply_number, :new_post, :last_update_time)"); + query.prepare("INSERT OR REPLACE INTO topics (forum_id, topic_id, topic_title, topic_author_id, topic_author_name, is_subscribed, is_closed, icon_url, last_reply_time, reply_number, new_post, position, last_update_time) " + "VALUES (:forum_id, :topic_id, :topic_title, :topic_author_id, :topic_author_name, :is_subscribed, :is_closed, :icon_url, :last_reply_time, :reply_number, :new_post, :position, :last_update_time)"); + + Q_ASSERT(_start >= 0); + int position = _start; foreach (const QVariant& topic_v, topics) { QVariantMap topic = topic_v.toMap(); @@ -91,8 +94,11 @@ void FetchTopicsAction::handleFinishedCall() query.bindValue(":last_reply_time", topic["last_reply_time"].toDateTime()); query.bindValue(":reply_number", topic["reply_number"].toInt()); query.bindValue(":new_post", topic["new_post"].toBool() ? 1 : 0); + query.bindValue(":position", position); query.bindValue(":last_update_time", QDateTime::currentDateTime()); + position++; + if (!query.exec()) { qWarning() << "Failed to store topic info for:" << topic_id; handleDatabaseError("storing topic info", query); @@ -101,15 +107,20 @@ void FetchTopicsAction::handleFinishedCall() } db.commit(); - if (topics.size() > 0) { + if (!topics.isEmpty()) { + Q_ASSERT(_start >= 0); + Q_ASSERT(position - 1 >= _start); _board->notifyForumTopicsChanged(_forumId, - _start, _start + topics.size() - 1); + _start, position - 1); } if (_end == FetchAllTopics && topics.size() == MAX_FORUM_PAGE_SIZE) { // Ok, let's prepare to fetch the next block of topics because // there are probably more of them - int start = _start + MAX_FORUM_PAGE_SIZE; - _board->enqueueAction(new FetchTopicsAction(_forumId, start, FetchAllTopics, _board)); + int next_start = _start + MAX_FORUM_PAGE_SIZE; + _board->enqueueAction(new FetchTopicsAction(_forumId, + next_start, + FetchAllTopics, + _board)); } } else { qWarning() << "Could not fetch topics"; |