summaryrefslogtreecommitdiff
path: root/fetchtopicsaction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fetchtopicsaction.cpp')
-rw-r--r--fetchtopicsaction.cpp23
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";