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

Add unique_end_date constraint to funding_rates table #2615

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

luckysori
Copy link
Contributor

We only need one funding rate entry per end_date.

Without this change we were getting a new duplicate entry per maker restart.

@luckysori luckysori requested review from bonomat and holzeis June 6, 2024 05:00
@luckysori luckysori self-assigned this Jun 6, 2024
@luckysori luckysori enabled auto-merge June 6, 2024 05:00
@holzeis
Copy link
Contributor

holzeis commented Jun 6, 2024

What will happen if we get a duplicate entry. Is the error simply logged?

@luckysori
Copy link
Contributor Author

luckysori commented Jun 6, 2024

What will happen if we get a duplicate entry. Is the error simply logged?

Good question.

An error would be logged, but it would also mean that any other rows in the batch would be ignored. I've updated the patch to fix this: https://github.com/get10101/10101/compare/fc36c9a54b22eeda84dccf463a872bc9c7b53543..23ac948ab64eda8cbe7a06abd343a0b62feb42f9.

@luckysori luckysori force-pushed the fix/duplicate-funding-rates branch from fc36c9a to 23ac948 Compare June 6, 2024 05:34
@luckysori luckysori requested review from holzeis and removed request for holzeis June 6, 2024 05:34
@@ -39,6 +39,8 @@ pub fn insert_funding_rates(

let affected_rows = diesel::insert_into(funding_rates::table)
.values(funding_rates)
.on_conflict(funding_rates::end_date)
.do_nothing()
.execute(conn)?;

if affected_rows == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 Maybe we don't want this either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I've removed it now :D

@luckysori luckysori force-pushed the fix/duplicate-funding-rates branch from 23ac948 to b9ddf11 Compare June 6, 2024 05:48
@luckysori luckysori requested a review from holzeis June 6, 2024 05:48
We only need one funding rate entry per `end_date`.

Without this change we were getting a new duplicate entry per
maker restart.

We `DO NOTHING` on conflict to ensure that the actually new rows in
the batch will be inserted if we encounter any conflicts.
@luckysori luckysori force-pushed the fix/duplicate-funding-rates branch from b9ddf11 to d0e6b43 Compare June 6, 2024 05:56
@luckysori luckysori added this pull request to the merge queue Jun 6, 2024
Merged via the queue into main with commit ee321aa Jun 6, 2024
23 checks passed
@luckysori luckysori deleted the fix/duplicate-funding-rates branch June 6, 2024 06:20
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.

2 participants