Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sorting: update cached part stock quantity if a mismatch with db is found #447

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ def populate_footprint_list(self, *_):
)
if detail:
part[4] = detail[0][2]
part[5] = detail[0][1]
if part[5] != str(detail[0][1]):
part[5] = str(detail[0][1])
self.store.set_stock(part[0], detail[0][1])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when would this condition occur? When the database is updated while the plugin is open, without closing and reopening the plugin?

Copy link
Contributor Author

@gyohng gyohng Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will occur persistently after updating a database while having some projects with LCSC components filled from before the update. Reopening the plugin doesn't help. self.store is project-bound and does not explicitly sync its stock quantity value with the database at all. There's just one path where it does - and that's when you use a part selector - and never afterwards. This fix is meant to address it. The condition is there not to call set_stock always, which works through sqlite.

If this code is not there, the sorting logic does not use the data from detail and only considers the non-overridden old once cached and never updated data inside part[5]

# First check if the part name mathes
for regex, correction in corrections:
if re.search(regex, str(part[1])):
Expand Down