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):
with sqlite3.connect("../db/sqlite3.db",timeout=10) as connection: viewedEntry.list = []
cursor = connection.cursor() viewedEntry.list.append(hash1)
cursor.execute("UPDATE jobs SET viewed = '1' WHERE hash = ?",(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) 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,15 +42,21 @@ class SqlQueryModel_editable(QSqlQueryModel):
print(self.query().lastError().text()) print(self.query().lastError().text())
return result return result
elif role == 1001: elif role == 1001:
print("Atempt flaging view") result = 0
q = QSqlQuery("UPDATE jobs SET viewed = '1' WHERE hash = {}".format(value)) self.updatelist.append(value)
print("QSQLQuery: ", "UPDATE jobs SET viewed = '1' WHERE hash = {}".format(value)) print(self.updatelist)
result = q.exec_() if len(self.updatelist) >= 5:
if result: for x in self.updatelist:
self.query().exec_() print("Atempt flaging view")
# print("filter_value:",filter_value) q = QSqlQuery("UPDATE jobs SET viewed = '1' WHERE hash = {}".format(x))
else: print("QSQLQuery: ", "UPDATE jobs SET viewed = '1' WHERE hash = {}".format(x))
print("Error:", self.query().lastError().text()) result = q.exec_()
if result:
self.query().exec_()
else:
print("Error:", self.query().lastError().text())
return result
self.updatelist = []
return result return result
return QSqlQueryModel.setData(self, index, value, role) return QSqlQueryModel.setData(self, index, value, role)