From 4fe4d0a7e793aef8e3d6807df88b14f17ffbe7fb Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sat, 16 Mar 2019 02:18:53 +0100 Subject: [PATCH] BEGIN / END no longer necessary as there is no autocommit in new db module --- plugins/Chart/ChartCollector.py | 4 ---- plugins/OptionalManager/ContentDbPlugin.py | 15 --------------- plugins/OptionalManager/OptionalManagerPlugin.py | 2 -- plugins/PeerDb/PeerDbPlugin.py | 3 --- .../disabled-Bootstrapper/BootstrapperPlugin.py | 2 -- src/Db/Db.py | 11 ----------- 6 files changed, 37 deletions(-) diff --git a/plugins/Chart/ChartCollector.py b/plugins/Chart/ChartCollector.py index ad4d11a8..bd5a1f84 100644 --- a/plugins/Chart/ChartCollector.py +++ b/plugins/Chart/ChartCollector.py @@ -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)) diff --git a/plugins/OptionalManager/ContentDbPlugin.py b/plugins/OptionalManager/ContentDbPlugin.py index f3716b44..b9f6552a 100644 --- a/plugins/OptionalManager/ContentDbPlugin.py +++ b/plugins/OptionalManager/ContentDbPlugin.py @@ -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() diff --git a/plugins/OptionalManager/OptionalManagerPlugin.py b/plugins/OptionalManager/OptionalManagerPlugin.py index 4e1b4336..3789a4c7 100644 --- a/plugins/OptionalManager/OptionalManagerPlugin.py +++ b/plugins/OptionalManager/OptionalManagerPlugin.py @@ -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() diff --git a/plugins/PeerDb/PeerDbPlugin.py b/plugins/PeerDb/PeerDbPlugin.py index 86613fc7..f26f1657 100644 --- a/plugins/PeerDb/PeerDbPlugin.py +++ b/plugins/PeerDb/PeerDbPlugin.py @@ -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): diff --git a/plugins/disabled-Bootstrapper/BootstrapperPlugin.py b/plugins/disabled-Bootstrapper/BootstrapperPlugin.py index a7ecbdba..64226dfd 100644 --- a/plugins/disabled-Bootstrapper/BootstrapperPlugin.py +++ b/plugins/disabled-Bootstrapper/BootstrapperPlugin.py @@ -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() diff --git a/src/Db/Db.py b/src/Db/Db.py index bcc36201..b48e52b5 100644 --- a/src/Db/Db.py +++ b/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"):