Skip to content

Commit

Permalink
Fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouni committed Aug 2, 2024
1 parent a3577dd commit d6a18ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 5 additions & 6 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def insert_parts(self, data, cols):
con.executemany(query, data)
con.commit()

def get_part_details(self, lcsc: list) -> dict:
def get_part_details(self, lcsc: list) -> list:
"""Get the part details for a list of LCSC numbers using optimized FTS5 querying."""
with contextlib.closing(sqlite3.connect(self.partsdb_file)) as con:
con.row_factory = dict_factory
Expand All @@ -390,11 +390,10 @@ def get_part_details(self, lcsc: list) -> dict:
query = '''SELECT "LCSC Part" AS lcsc, "Stock" AS stock, "Library Type" AS type FROM parts WHERE parts MATCH :number LIMIT 1'''
# Use parameter binding to prevent SQL injection and handle the query more efficiently
for number in lcsc:
cur.execute(query, {"number": number})
results.extend([x for x in cur.fetchall() if x[0] == number]) # Filter exact match as FTS5 does return every match
if results:
return results[0]
return {}
self.logger.debug(number)
cur.execute(query, {"number": f'"{number}"'})
results.extend([x for x in cur.fetchall() if x["lcsc"] == number]) # Filter exact match as FTS5 does return every match
return results

def update(self):
"""Update the sqlite parts database from the JLCPCB CSV."""
Expand Down
12 changes: 9 additions & 3 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,15 @@ def populate_footprint_list(self, *_):
corrections = self.library.get_all_correction_data()
# find rotation correction values
for part in parts:
if details:
part["type"] = details["type"]
part["stock"] = details["stock"]
detail = list(
filter(
lambda x, lcsc=part["lcsc"]: x["lcsc"] == lcsc,
details,
)
)
if detail:
part["type"] = detail[0]["type"]
part["stock"] = detail[0]["stock"]
# First check if the part name mathes
for regex, correction in corrections:
if re.search(regex, str(part["reference"])):
Expand Down

0 comments on commit d6a18ad

Please sign in to comment.