From 81ed31be794959fc1efc5a0be806d4bbf52bebf5 Mon Sep 17 00:00:00 2001 From: George Yohng Date: Mon, 22 Apr 2024 18:41:57 +0800 Subject: [PATCH] Fix: speed up index creating by reading more parts at once --- library.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library.py b/library.py index 2731ecc..26ee417 100644 --- a/library.py +++ b/library.py @@ -530,15 +530,14 @@ def download(self): self.logger.debug("Indexing parts table...") wx.PostEvent(self.parent, UpdateGaugeEvent(value=0)) with contextlib.closing(sqlite3.connect(self.partsdb_file)) as con: + con.execute('DROP TABLE parts_by_lcsc;') con.execute('CREATE TABLE IF NOT EXISTS parts_by_lcsc (partsId INTEGER, lcsc TEXT);') - howMany = con.execute('SELECT COUNT(*) FROM parts').fetchone()[0] con.execute('DROP INDEX IF EXISTS LCSCpartIdx;') cur = con.execute('SELECT rowid, `LCSC Part` FROM parts') + indexedParts = cur.fetchall() + howMany = len(indexedParts) progress = 0 - for i in range(howMany): - r = cur.fetchone() - if r is None: - break + for i, r in enumerate(indexedParts): con.execute('INSERT OR REPLACE INTO parts_by_lcsc (partsId, lcsc) VALUES (?, ?)', (r[0], r[1])) p = int(i / howMany * 100) if p > progress: @@ -550,6 +549,7 @@ def download(self): con.commit() con.execute('CREATE INDEX IF NOT EXISTS LCSCpartIdx ON parts_by_lcsc(lcsc);') con.commit() + self.logger.debug("Indexing parts table done.") wx.PostEvent(self.parent, ResetGaugeEvent()) end = time.time()