From 71209e9b5fc3aa263a6d1977a5246dfb91d3e37f Mon Sep 17 00:00:00 2001 From: ccppi Date: Wed, 7 Aug 2024 11:08:39 +0200 Subject: [PATCH] batching together some transaction for performance sacke --- lib/db.py | 13 ++++++++++--- lib/qsqlmod.py | 25 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/db.py b/lib/db.py index 4e5ec20..e83cfe9 100644 --- a/lib/db.py +++ b/lib/db.py @@ -96,9 +96,16 @@ def writedb(jobs): cursor.execute("INSERT INTO jobs (star,tag,title,company,location,link,pubdate,hash,viewed) VALUES (?,?,?,?,?,?,?,?,?)",(job.starred,job.tag,job.title,job.company,job.location,job.link,job.date,hash1,0)) def viewedEntry(hash1): - with sqlite3.connect("../db/sqlite3.db",timeout=10) as connection: - cursor = connection.cursor() - cursor.execute("UPDATE jobs SET viewed = '1' WHERE hash = ?",(hash1,)) + viewedEntry.list = [] + viewedEntry.list.append(hash1) + print("viewedEntry.list:",viewedEntry.list) + if len(viewedEntry.list) >= 5: + with sqlite3.connect("../db/sqlite3.db",timeout=10) as connection: + cursor = connection.cursor() + for x in viewedEntry.list: + print("hash:",x) + cursor.execute("UPDATE jobs SET viewed = '1' WHERE hash = ?",(x,)) + viewedEntry.list = [] print("modified rows: ",cursor.rowcount) diff --git a/lib/qsqlmod.py b/lib/qsqlmod.py index 0d83539..05f18fd 100644 --- a/lib/qsqlmod.py +++ b/lib/qsqlmod.py @@ -16,6 +16,7 @@ class SqlQueryModel_editable(QSqlQueryModel): """ super().__init__() self.editables = editables + self.updatelist = [] def flags(self, index): fl = QSqlQueryModel.flags(self, index) @@ -41,15 +42,21 @@ class SqlQueryModel_editable(QSqlQueryModel): print(self.query().lastError().text()) return result elif role == 1001: - print("Atempt flaging view") - q = QSqlQuery("UPDATE jobs SET viewed = '1' WHERE hash = {}".format(value)) - print("QSQLQuery: ", "UPDATE jobs SET viewed = '1' WHERE hash = {}".format(value)) - result = q.exec_() - if result: - self.query().exec_() -# print("filter_value:",filter_value) - else: - print("Error:", self.query().lastError().text()) + result = 0 + self.updatelist.append(value) + print(self.updatelist) + if len(self.updatelist) >= 5: + for x in self.updatelist: + print("Atempt flaging view") + q = QSqlQuery("UPDATE jobs SET viewed = '1' WHERE hash = {}".format(x)) + print("QSQLQuery: ", "UPDATE jobs SET viewed = '1' WHERE hash = {}".format(x)) + result = q.exec_() + if result: + self.query().exec_() + else: + print("Error:", self.query().lastError().text()) + return result + self.updatelist = [] return result return QSqlQueryModel.setData(self, index, value, role)