This commit is contained in:
Martin Rotter 2023-12-11 13:26:45 +01:00
parent 95c2e266e7
commit bcc715e83e
4 changed files with 22 additions and 18 deletions

View file

@ -181,6 +181,7 @@ QJsonObject Message::toJson() const {
obj.insert(QSL("id"), m_id); obj.insert(QSL("id"), m_id);
obj.insert(QSL("custom_id"), m_customId); obj.insert(QSL("custom_id"), m_customId);
obj.insert(QSL("custom_hash"), m_customHash); obj.insert(QSL("custom_hash"), m_customHash);
obj.insert(QSL("feed_custom_id"), m_feedId);
obj.insert(QSL("enclosures"), Enclosures::encodeEnclosuresToJson(m_enclosures)); obj.insert(QSL("enclosures"), Enclosures::encodeEnclosuresToJson(m_enclosures));
return obj; return obj;

View file

@ -1174,32 +1174,35 @@ QList<Message> DatabaseQueries::getUndeletedUnreadMessages(const QSqlDatabase& d
return messages; return messages;
} }
QList<Message> DatabaseQueries::getFeedsSlice(const QSqlDatabase& db, QList<Message> DatabaseQueries::getArticlesSlice(const QSqlDatabase& db,
const QString& feed_custom_id, const QString& feed_custom_id,
int account_id, int account_id,
bool newest_first, bool newest_first,
bool unread_only, bool unread_only,
int row_offset, int row_offset,
int row_limit) { int row_limit) {
QList<Message> messages; QList<Message> messages;
QSqlQuery q(db); QSqlQuery q(db);
QString feed_clause = !feed_custom_id.isEmpty() ? QSL("feed = :feed AND") : QString();
q.setForwardOnly(true); q.setForwardOnly(true);
q.prepare(QSL("SELECT %1 " q.prepare(QSL("SELECT %1 "
"FROM Messages " "FROM Messages "
"WHERE is_deleted = 0 AND " "WHERE is_deleted = 0 AND "
" is_pdeleted = 0 AND " " is_pdeleted = 0 AND "
" is_read = :is_read AND " " is_read = :is_read AND "
" feed = :feed AND " " %3 "
" account_id = :account_id " " account_id = :account_id "
"ORDER BY Messages.date_created %2 " "ORDER BY Messages.date_created %2 "
"LIMIT :row_limit OFFSET :row_offset;") "LIMIT :row_limit OFFSET :row_offset;")
.arg(messageTableAttributes(true, db.driverName() == QSL(APP_DB_SQLITE_DRIVER)).values().join(QSL(", ")), .arg(messageTableAttributes(true, db.driverName() == QSL(APP_DB_SQLITE_DRIVER)).values().join(QSL(", ")),
newest_first ? QSL("DESC") : QSL("ASC"))); newest_first ? QSL("DESC") : QSL("ASC"),
q.bindValue(QSL(":feed"), feed_custom_id); feed_clause));
q.bindValue(QSL(":account_id"), account_id); q.bindValue(QSL(":account_id"), account_id);
q.bindValue(QSL(":row_limit"), row_limit); q.bindValue(QSL(":row_limit"), row_limit);
q.bindValue(QSL(":row_offset"), row_offset); q.bindValue(QSL(":row_offset"), row_offset);
q.bindValue(QSL(":feed"), QSL("feed"));
if (unread_only) { if (unread_only) {
q.bindValue(QSL(":is_read"), 0); q.bindValue(QSL(":is_read"), 0);

View file

@ -118,13 +118,13 @@ class DatabaseQueries {
static QList<Message> getUndeletedMessagesForBin(const QSqlDatabase& db, int account_id, bool* ok = nullptr); static QList<Message> getUndeletedMessagesForBin(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static QList<Message> getUndeletedMessagesForAccount(const QSqlDatabase& db, int account_id, bool* ok = nullptr); static QList<Message> getUndeletedMessagesForAccount(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static QList<Message> getFeedsSlice(const QSqlDatabase& db, static QList<Message> getArticlesSlice(const QSqlDatabase& db,
const QString& feed_custom_id, const QString& feed_custom_id,
int account_id, int account_id,
bool newest_first, bool newest_first,
bool unread_only, bool unread_only,
int row_offset, int row_offset,
int row_limit); int row_limit);
// Custom ID accumulators. // Custom ID accumulators.
static QStringList bagOfMessages(const QSqlDatabase& db, ServiceRoot::BagOfMessages bag, const Feed* feed); static QStringList bagOfMessages(const QSqlDatabase& db, ServiceRoot::BagOfMessages bag, const Feed* feed);

View file

@ -81,7 +81,7 @@ ApiResponse ApiServer::processArticlesFromFeed(const QJsonValue& req) const {
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
QList<Message> msgs = QList<Message> msgs =
DatabaseQueries::getFeedsSlice(database, feed_id, account_id, newest_first, unread_only, row_offset, row_limit); DatabaseQueries::getArticlesSlice(database, feed_id, account_id, newest_first, unread_only, row_offset, row_limit);
QJsonArray msgs_json_array; QJsonArray msgs_json_array;
for (const Message& msg : msgs) { for (const Message& msg : msgs) {