Skip to content

Commit

Permalink
Fix: speed up index creating by reading more parts at once
Browse files Browse the repository at this point in the history
  • Loading branch information
gyohng committed Apr 22, 2024
1 parent 56d38ec commit 81ed31b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit 81ed31b

Please sign in to comment.