-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add v2 file contract revisions #133
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left some nits and suggestions on fillV2TransactionFileContractRevisions
persist/sqlite/v2transactions.go
Outdated
} | ||
|
||
if len(parents) != len(revisions) { | ||
panic("should have a parent for every v2 revision contract") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this panic
absolutely necessary? I can see how we want to, in some cases, panic when we have db corruption but seems quite harsh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the statements can be combined using UNION ALL
, you add something like "SELECT "parent", ... UNION ALL SELECT "revision"
to differentiate the two and then collectFileContracts
returns two slices.
var kind string
if err := rows.Scan(&kind); err != nil {
return nil, fmt.Errorf("failed to scan contract type: %w", err)
}
fce, err := scanV2FileContract(rows)
if err != nil {
return nil, fmt.Errorf("failed to scan file contract: %w", err)
}
if kind == "parent" {
parents = append(contracts, fce)
} else {
revisions = append(contracts, fce)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how well this would perform but something this would get rid of the duplicate select expression and clearly show what's happening.
WITH
base_data AS (SELECT field1, field2, field3 FROM t1 INNER JOIN t2),
revision_data AS (SELECT *, "revision" as kind FROM base_data),
parent_data AS (SELECT *, "parent" as kind FROM base_data)
SELECT * FROM revision_data ORDER BY x
UNION ALL
SELECT * FROM parent_data ORDER BY x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried doing something along these lines but I don't think this is worth it unless we find we're having performance issues with the current queries. It makes the query more complicated and it seems that calling Scan twice on the same Rows doesn't work so we'd need to change the FCE scan helper too because we can't get the kind
separately from the rest of the data.
No description provided.