Skip to content

Commit

Permalink
Merge pull request #115 from helium/mbthiery/debug-23-12-21
Browse files Browse the repository at this point in the history
Add guard to avoid primary key conflict
  • Loading branch information
mbthiery authored Dec 21, 2023
2 parents 8441443 + 7c9cbd1 commit cd587cd
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit cd587cd

Please sign in to comment.