usa thread safe db where makes sense

This commit is contained in:
Martin Rotter 2023-01-06 13:40:17 +01:00
parent 15e4f8e31f
commit b0cc456087
8 changed files with 12 additions and 38 deletions

View File

@ -60,7 +60,7 @@
<content_rating type="oars-1.0" /> <content_rating type="oars-1.0" />
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="4.2.7" date="2023-01-05" /> <release version="4.2.7" date="2023-01-06" />
</releases> </releases>
<provides> <provides>
<binary>@APP_LOW_NAME@</binary> <binary>@APP_LOW_NAME@</binary>

View File

@ -223,9 +223,7 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
tmr.start(); tmr.start();
try { try {
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd_%1").arg(thread_id));
QList<Message> msgs = feed->getParentServiceRoot()->obtainNewMessages(feed, stated_messages, tagged_messages); QList<Message> msgs = feed->getParentServiceRoot()->obtainNewMessages(feed, stated_messages, tagged_messages);
qDebugNN << LOGSEC_FEEDDOWNLOADER << "Downloaded" << NONQUOTE_W_SPACE(msgs.size()) << "messages for feed ID" qDebugNN << LOGSEC_FEEDDOWNLOADER << "Downloaded" << NONQUOTE_W_SPACE(msgs.size()) << "messages for feed ID"

View File

@ -196,11 +196,7 @@ void Feed::appendMessageFilter(MessageFilter* filter) {
} }
void Feed::updateCounts(bool including_total_count) { void Feed::updateCounts(bool including_total_count) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
qlonglong thread_id = qlonglong(QThread::currentThreadId());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd_%1").arg(thread_id));
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
if (including_total_count) { if (including_total_count) {

View File

@ -25,10 +25,7 @@ QList<Message> ImportantNode::undeletedMessages() const {
} }
void ImportantNode::updateCounts(bool including_total_count) { void ImportantNode::updateCounts(bool including_total_count) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
qlonglong thread_id = qlonglong(QThread::currentThreadId());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd_%1").arg(thread_id));
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
if (including_total_count) { if (including_total_count) {

View File

@ -76,10 +76,7 @@ bool Label::deleteViaGui() {
} }
void Label::updateCounts(bool including_total_count) { void Label::updateCounts(bool including_total_count) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
qlonglong thread_id = qlonglong(QThread::currentThreadId());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd_%1").arg(thread_id));
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
if (including_total_count) { if (including_total_count) {
@ -110,9 +107,7 @@ QIcon Label::generateIcon(const QColor& color) {
} }
void Label::assignToMessage(const Message& msg) { void Label::assignToMessage(const Message& msg) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd"));
if (getParentServiceRoot()->onBeforeLabelMessageAssignmentChanged({this}, {msg}, true)) { if (getParentServiceRoot()->onBeforeLabelMessageAssignmentChanged({this}, {msg}, true)) {
DatabaseQueries::assignLabelToMessage(database, this, msg); DatabaseQueries::assignLabelToMessage(database, this, msg);
@ -122,9 +117,7 @@ void Label::assignToMessage(const Message& msg) {
} }
void Label::deassignFromMessage(const Message& msg) { void Label::deassignFromMessage(const Message& msg) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd"));
if (getParentServiceRoot()->onBeforeLabelMessageAssignmentChanged({this}, {msg}, false)) { if (getParentServiceRoot()->onBeforeLabelMessageAssignmentChanged({this}, {msg}, false)) {
DatabaseQueries::deassignLabelFromMessage(database, this, msg); DatabaseQueries::deassignLabelFromMessage(database, this, msg);

View File

@ -32,10 +32,7 @@ int RecycleBin::countOfAllMessages() const {
} }
void RecycleBin::updateCounts(bool update_total_count) { void RecycleBin::updateCounts(bool update_total_count) {
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
qlonglong thread_id = qlonglong(QThread::currentThreadId());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd_%1").arg(thread_id));
m_unreadCount = DatabaseQueries::getMessageCountsForBin(database, getParentServiceRoot()->accountId(), false); m_unreadCount = DatabaseQueries::getMessageCountsForBin(database, getParentServiceRoot()->accountId(), false);

View File

@ -954,14 +954,10 @@ QPair<int, int> ServiceRoot::updateMessages(QList<Message>& messages, Feed* feed
} }
QList<RootItem*> items_to_update; QList<RootItem*> items_to_update;
bool is_main_thread = QThread::currentThread() == qApp->thread();
qDebugNN << LOGSEC_CORE << "Updating messages in DB. Main thread:" << QUOTE_W_SPACE_DOT(is_main_thread);
bool ok = false; bool ok = false;
qlonglong thread_id = qlonglong(QThread::currentThreadId()); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd_%1").arg(thread_id)); qDebugNN << LOGSEC_CORE << "Updating messages in DB.";
updated_messages = DatabaseQueries::updateMessages(database, messages, feed, force_update, &ok); updated_messages = DatabaseQueries::updateMessages(database, messages, feed, force_update, &ok);

View File

@ -25,10 +25,7 @@ QList<Message> UnreadNode::undeletedMessages() const {
void UnreadNode::updateCounts(bool including_total_count) { void UnreadNode::updateCounts(bool including_total_count) {
Q_UNUSED(including_total_count) Q_UNUSED(including_total_count)
bool is_main_thread = QThread::currentThread() == qApp->thread(); QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
qlonglong thread_id = qlonglong(QThread::currentThreadId());
QSqlDatabase database = is_main_thread ? qApp->database()->driver()->connection(metaObject()->className())
: qApp->database()->driver()->connection(QSL("feed_upd_%1").arg(thread_id));
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
m_totalCount = m_unreadCount = DatabaseQueries::getUnreadMessageCounts(database, account_id); m_totalCount = m_unreadCount = DatabaseQueries::getUnreadMessageCounts(database, account_id);