BEGIN / END no longer necessary as there is no autocommit in new db module
This commit is contained in:
parent
a46d8fe7f3
commit
4fe4d0a7e7
6 changed files with 0 additions and 37 deletions
|
@ -144,9 +144,7 @@ class ChartCollector(object):
|
|||
|
||||
s = time.time()
|
||||
cur = self.db.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
cur.cursor.executemany("INSERT INTO data (type_id, value, date_added) VALUES (?, ?, ?)", values)
|
||||
cur.execute("END")
|
||||
cur.close()
|
||||
self.log.debug("Global collectors inserted in %.3fs" % (time.time() - s))
|
||||
|
||||
|
@ -163,9 +161,7 @@ class ChartCollector(object):
|
|||
|
||||
s = time.time()
|
||||
cur = self.db.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
cur.cursor.executemany("INSERT INTO data (type_id, site_id, value, date_added) VALUES (?, ?, ?, ?)", values)
|
||||
cur.execute("END")
|
||||
cur.close()
|
||||
self.log.debug("Site collectors inserted in %.3fs" % (time.time() - s))
|
||||
|
||||
|
|
|
@ -126,7 +126,6 @@ class ContentDbPlugin(object):
|
|||
if not site_id:
|
||||
return False
|
||||
cur = self.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
res = cur.execute("SELECT * FROM content WHERE size_files_optional > 0 AND site_id = %s" % site_id)
|
||||
num = 0
|
||||
for row in res.fetchall():
|
||||
|
@ -135,7 +134,6 @@ class ContentDbPlugin(object):
|
|||
num += self.setContentFilesOptional(site, row["inner_path"], content, cur=cur)
|
||||
except Exception as err:
|
||||
self.log.error("Error loading %s into file_optional: %s" % (row["inner_path"], err))
|
||||
cur.execute("COMMIT")
|
||||
cur.close()
|
||||
|
||||
# Set my files to pinned
|
||||
|
@ -158,10 +156,6 @@ class ContentDbPlugin(object):
|
|||
def setContentFilesOptional(self, site, content_inner_path, content, cur=None):
|
||||
if not cur:
|
||||
cur = self
|
||||
try:
|
||||
cur.execute("BEGIN")
|
||||
except Exception as err:
|
||||
self.log.warning("Transaction begin error %s %s: %s" % (site, content_inner_path, Debug.formatException(err)))
|
||||
|
||||
num = 0
|
||||
site_id = self.site_ids[site.address]
|
||||
|
@ -193,11 +187,6 @@ class ContentDbPlugin(object):
|
|||
self.optional_files[site_id][file_inner_path[-8:]] = 1
|
||||
num += 1
|
||||
|
||||
if cur == self:
|
||||
try:
|
||||
cur.execute("END")
|
||||
except Exception as err:
|
||||
self.log.warning("Transaction end error %s %s: %s" % (site, content_inner_path, Debug.formatException(err)))
|
||||
return num
|
||||
|
||||
def setContent(self, site, inner_path, content, size=0):
|
||||
|
@ -269,10 +258,8 @@ class ContentDbPlugin(object):
|
|||
if peer_num != row["peer"]:
|
||||
updates[row["file_id"]] = peer_num
|
||||
|
||||
self.execute("BEGIN")
|
||||
for file_id, peer_num in updates.items():
|
||||
self.execute("UPDATE file_optional SET peer = ? WHERE file_id = ?", (peer_num, file_id))
|
||||
self.execute("END")
|
||||
|
||||
num_updated += len(updates)
|
||||
num_file += len(peer_nums)
|
||||
|
@ -415,8 +402,6 @@ class ContentDbPlugin(object):
|
|||
break
|
||||
|
||||
cur = self.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
for file_id in deleted_file_ids:
|
||||
cur.execute("UPDATE file_optional SET is_downloaded = 0, is_pinned = 0, peer = peer - 1 WHERE ?", {"file_id": file_id})
|
||||
cur.execute("COMMIT")
|
||||
cur.close()
|
||||
|
|
|
@ -35,7 +35,6 @@ def processRequestLog():
|
|||
content_db = ContentDbPlugin.content_db
|
||||
cur = content_db.getCursor()
|
||||
num = 0
|
||||
cur.execute("BEGIN")
|
||||
for site_id in request_log:
|
||||
for inner_path, uploaded in request_log[site_id].items():
|
||||
content_db.execute(
|
||||
|
@ -43,7 +42,6 @@ def processRequestLog():
|
|||
{"site_id": site_id, "inner_path": inner_path}
|
||||
)
|
||||
num += 1
|
||||
cur.execute("END")
|
||||
request_log.clear()
|
||||
|
||||
|
||||
|
|
|
@ -77,7 +77,6 @@ class ContentDbPlugin(object):
|
|||
s = time.time()
|
||||
site_id = self.site_ids.get(site.address)
|
||||
cur = self.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
try:
|
||||
cur.execute("DELETE FROM peer WHERE site_id = :site_id", {"site_id": site_id})
|
||||
cur.cursor.executemany(
|
||||
|
@ -86,8 +85,6 @@ class ContentDbPlugin(object):
|
|||
)
|
||||
except Exception as err:
|
||||
site.log.error("Save peer error: %s" % err)
|
||||
finally:
|
||||
cur.execute("END")
|
||||
site.log.debug("Peers saved in %.3fs" % (time.time() - s))
|
||||
|
||||
def initSite(self, site):
|
||||
|
|
|
@ -69,7 +69,6 @@ class FileRequestPlugin(object):
|
|||
i += 1
|
||||
|
||||
hashes_changed = 0
|
||||
db.execute("BEGIN")
|
||||
for onion, onion_hashes in onion_to_hash.items():
|
||||
hashes_changed += db.peerAnnounce(
|
||||
ip_type="onion",
|
||||
|
@ -78,7 +77,6 @@ class FileRequestPlugin(object):
|
|||
hashes=onion_hashes,
|
||||
onion_signed=all_onions_signed
|
||||
)
|
||||
db.execute("END")
|
||||
time_db_onion = time.time() - s
|
||||
|
||||
s = time.time()
|
||||
|
|
11
src/Db/Db.py
11
src/Db/Db.py
|
@ -98,7 +98,6 @@ class Db(object):
|
|||
|
||||
s = time.time()
|
||||
cur = self.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
for command, params in self.delayed_queue:
|
||||
if command == "insertOrUpdate":
|
||||
cur.insertOrUpdate(*params[0], **params[1])
|
||||
|
@ -165,8 +164,6 @@ class Db(object):
|
|||
changed_tables = []
|
||||
cur = self.getCursor()
|
||||
|
||||
cur.execute("BEGIN")
|
||||
|
||||
# Check internal tables
|
||||
# Check keyvalue table
|
||||
changed = cur.needTable("keyvalue", [
|
||||
|
@ -221,7 +218,6 @@ class Db(object):
|
|||
except Exception as err:
|
||||
self.log.error("Error creating table %s: %s" % (table_name, Debug.formatException(err)))
|
||||
|
||||
cur.execute("COMMIT")
|
||||
self.log.debug("Db check done in %.3fs, changed tables: %s" % (time.time() - s, changed_tables))
|
||||
if changed_tables:
|
||||
self.db_keyvalues = {} # Refresh table version cache
|
||||
|
@ -267,11 +263,7 @@ class Db(object):
|
|||
# No cursor specificed
|
||||
if not cur:
|
||||
cur = self.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
cur.logging = False
|
||||
commit_after_done = True
|
||||
else:
|
||||
commit_after_done = False
|
||||
|
||||
# Row for current json file if required
|
||||
if not data or [dbmap for dbmap in matched_maps if "to_keyvalue" in dbmap or "to_table" in dbmap]:
|
||||
|
@ -379,8 +371,6 @@ class Db(object):
|
|||
self.log.debug("Cleanup json row for %s" % file_path)
|
||||
cur.execute("DELETE FROM json WHERE json_id = %s" % json_row["json_id"])
|
||||
|
||||
if commit_after_done:
|
||||
cur.execute("COMMIT")
|
||||
return True
|
||||
|
||||
|
||||
|
@ -394,7 +384,6 @@ if __name__ == "__main__":
|
|||
dbjson.collect_stats = True
|
||||
dbjson.checkTables()
|
||||
cur = dbjson.getCursor()
|
||||
cur.execute("BEGIN")
|
||||
cur.logging = False
|
||||
dbjson.updateJson("data/users/content.json", cur=cur)
|
||||
for user_dir in os.listdir("data/users"):
|
||||
|
|
Loading…
Reference in a new issue