feat: add is_extended_promotional column to all component tables#138
Open
usernametooshort wants to merge 1 commit intotscircuit:mainfrom
Open
feat: add is_extended_promotional column to all component tables#138usernametooshort wants to merge 1 commit intotscircuit:mainfrom
usernametooshort wants to merge 1 commit intotscircuit:mainfrom
Conversation
Adds the is_extended_promotional field to: - BaseComponent interface (component-base.ts) - All 37 derived component tables - A new DB optimization (component-extended-promotional-column.ts) that adds the column to the base components table via a SQLite generated column using json_extract(extra, '$.promotional') The value is sourced from the 'promotional' key in the component's extra JSON field, consistent with how is_basic / is_preferred are derived. Fixes tscircuit#92 /bounty $75
| in_stock: c.stock > 0, | ||
| is_basic: Boolean(c.basic), | ||
| is_preferred: Boolean(c.preferred), | ||
| is_extended_promotional: Boolean(c.extra && JSON.parse(c.extra).promotional), |
Contributor
There was a problem hiding this comment.
Inconsistent boolean conversion logic across base and derived tables
The derived tables use Boolean(c.extra && JSON.parse(c.extra).promotional) which treats the string "false" as truthy, while the base table's GENERATED column in component-extended-promotional-column.ts explicitly checks != 'false' to treat it as falsy.
This creates data inconsistency:
- If
promotional: "false"(string): derived tables returntrue, base table returnsfalse - Components will have mismatched values between base and derived tables
Fix by aligning the logic:
is_extended_promotional: Boolean(
c.extra &&
JSON.parse(c.extra).promotional &&
JSON.parse(c.extra).promotional !== 'false'
)Or better, cache the parsed value to avoid parsing twice and handle edge cases.
Suggested change
| is_extended_promotional: Boolean(c.extra && JSON.parse(c.extra).promotional), | |
| is_extended_promotional: (() => { if (!c.extra) return false; try { const parsed = JSON.parse(c.extra); return Boolean(parsed.promotional && parsed.promotional !== 'false'); } catch { return false; } })(), |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #92
Summary
Adds
is_extended_promotionalto all component tables and the basecomponentstable.Changes
component-base.ts: Addedis_extended_promotional: booleantoBaseComponentinterfacejson_extract(extra, "$.promotional")component-extended-promotional-column.ts: Addsis_extended_promotionalas a SQLiteGENERATED ALWAYS AScolumn on the basecomponentstable, with an indexData Source
The value is derived from
extraJSON field:json_extract(extra, "$.promotional"), which is the same source used by jlcparts. This is consistent with howbasicandpreferredare stored.Testing
in_stockandis_basiccolumns