Skip to content

Commit

Permalink
Update core_purchase.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ftkg committed Oct 26, 2023
1 parent 18dc6ad commit 9c48db9
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions server/core_purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,26 @@ func upsertPurchases(ctx context.Context, db *sql.DB, purchases []*storagePurcha
rawResponseParams := make([]string, 0, len(purchases))
environmentParams := make([]api.StoreEnvironment, 0, len(purchases))
refundTimeParams := make([]time.Time, 0, len(purchases))

for _, purchase := range purchases {
if purchase.refundTime.IsZero() {
purchase.refundTime = time.Unix(0, 0)
}
if purchase.rawResponse == "" {
purchase.rawResponse = "{}"
}
transactionIDsToPurchase[purchase.transactionId] = purchase

userIdParams = append(userIdParams, purchase.userID)
storeParams = append(storeParams, purchase.store)
transactionIdParams = append(transactionIdParams, purchase.transactionId)
productIdParams = append(productIdParams, purchase.productId)
purchaseTimeParams = append(purchaseTimeParams, purchase.purchaseTime)
rawResponseParams = append(rawResponseParams, purchase.rawResponse)
environmentParams = append(environmentParams, purchase.environment)
refundTimeParams = append(refundTimeParams, purchase.refundTime)
}

query := `
INSERT INTO purchase
(
Expand All @@ -593,25 +613,6 @@ RETURNING
refund_time
`

for _, purchase := range purchases {
if purchase.refundTime.IsZero() {
purchase.refundTime = time.Unix(0, 0)
}
if purchase.rawResponse == "" {
purchase.rawResponse = "{}"
}
transactionIDsToPurchase[purchase.transactionId] = purchase
//batch.Queue(query, purchase.userID, purchase.store, purchase.transactionId, purchase.productId, purchase.purchaseTime, purchase.rawResponse, purchase.environment, purchase.refundTime)
userIdParams = append(userIdParams, purchase.userID)
storeParams = append(storeParams, purchase.store)
transactionIdParams = append(transactionIdParams, purchase.transactionId)
productIdParams = append(productIdParams, purchase.productId)
purchaseTimeParams = append(purchaseTimeParams, purchase.purchaseTime)
rawResponseParams = append(rawResponseParams, purchase.rawResponse)
environmentParams = append(environmentParams, purchase.environment)
refundTimeParams = append(refundTimeParams, purchase.refundTime)
}

rows, err := db.QueryContext(ctx, query, userIdParams, storeParams, transactionIdParams, productIdParams, purchaseTimeParams, rawResponseParams, environmentParams, refundTimeParams)
if err != nil {
return nil, err
Expand Down

0 comments on commit 9c48db9

Please sign in to comment.