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 guard to avoid primary key conflict #115

Merged
merged 1 commit into from
Dec 21, 2023
Merged
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
9 changes: 8 additions & 1 deletion src/knex/maxSupply.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { epochFromDate } from "@/app/stats/utils"
import { isEqual } from "date-fns"
import { Knex } from "knex"

type MaxSupplyRecord = {
Expand Down Expand Up @@ -65,7 +66,13 @@ export class MaxSupply {
// true when first recording of the day happens between treasury and HST emissions
(isSameDay && (latest?.supply || 0) < record.supply)
) {
await this.addRecord(record)
// guard to avoid duplicate entry for primary key
if (
!isEqual(record.recorded_at, latest?.recorded_at || 0) &&
!isEqual(record.recorded_at, latestBurn?.recorded_at || 0)
) {
await this.addRecord(record)
}
if (record.hnt_burned === BigInt(0)) return record
if (!latest && !latestBurn) return record
}
Expand Down