batching together some transaction for performance sacke

This commit is contained in:
ccppi 2024-08-07 11:08:39 +02:00
parent d37f451297
commit 71209e9b5f
2 changed files with 26 additions and 12 deletions

View File

@ -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)) 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): def viewedEntry(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: with sqlite3.connect("../db/sqlite3.db",timeout=10) as connection:
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("UPDATE jobs SET viewed = '1' WHERE hash = ?",(hash1,)) 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) print("modified rows: ",cursor.rowcount)

View File

@ -16,6 +16,7 @@ class SqlQueryModel_editable(QSqlQueryModel):
""" """
super().__init__() super().__init__()
self.editables = editables self.editables = editables
self.updatelist = []
def flags(self, index): def flags(self, index):
fl = QSqlQueryModel.flags(self, index) fl = QSqlQueryModel.flags(self, index)
@ -41,16 +42,22 @@ class SqlQueryModel_editable(QSqlQueryModel):
print(self.query().lastError().text()) print(self.query().lastError().text())
return result return result
elif role == 1001: elif role == 1001:
result = 0
self.updatelist.append(value)
print(self.updatelist)
if len(self.updatelist) >= 5:
for x in self.updatelist:
print("Atempt flaging view") print("Atempt flaging view")
q = QSqlQuery("UPDATE jobs SET viewed = '1' WHERE hash = {}".format(value)) q = QSqlQuery("UPDATE jobs SET viewed = '1' WHERE hash = {}".format(x))
print("QSQLQuery: ", "UPDATE jobs SET viewed = '1' WHERE hash = {}".format(value)) print("QSQLQuery: ", "UPDATE jobs SET viewed = '1' WHERE hash = {}".format(x))
result = q.exec_() result = q.exec_()
if result: if result:
self.query().exec_() self.query().exec_()
# print("filter_value:",filter_value)
else: else:
print("Error:", self.query().lastError().text()) print("Error:", self.query().lastError().text())
return result return result
self.updatelist = []
return result
return QSqlQueryModel.setData(self, index, value, role) return QSqlQueryModel.setData(self, index, value, role)