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

Conversation

gyohng
Copy link
Contributor

@gyohng gyohng commented Apr 21, 2024

This patch corrects a sorting issue in the application where the GUI displayed the correct stock quantities but used outdated cached values for sorting operations.

The fix targets the populate_footprint_list method and involves a condition that checks if the cached stock value (part[5]) in the GUI matches the most recent stock quantity from the database (detail[0][1]). If a mismatch is detected, the cached value is updated to the current database value, and also set_stock is called, which updates the current board database with the new stock values.

…se the cached field is used for sorting directly.
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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants