Skip to content

Commit

Permalink
smarter bulk price fetches
Browse files Browse the repository at this point in the history
Previously, any single card for a batch would compromise the entire set
of prices. This allows up to 1/3 of a bulk fetch to fail.

closes #11
  • Loading branch information
Everlag committed Jan 3, 2016
1 parent 17fabf6 commit 355ab1c
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions common/priceDB/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@ package priceDB

import (
"github.com/jackc/pgx"

"fmt"
)

func GetBulkLatestLowest(pool *pgx.ConnPool,
names []string, source string) (Prices, error) {

result:= make(Prices, len(names))

failed:= 0

for i, c:= range names {
p, err:= GetCardLatestLowest(pool, c, source)
if err!=nil {
return nil, err
// Record this as a failure
failed++

// Insert a placeholder
p = Price{
Name: c,
Set: "Unknown",
Price: -1,
Source: source,
}
}

result[i] = p
}

// If we fail to fetch more than 1/3 of prices for this bulk
// set, we error out
if failed >= len(names) / 3 {
return nil, fmt.Errorf("too many fetch failures")
}

return result, nil
}

Expand All @@ -26,14 +45,31 @@ func GetBulkLatestHighest(pool *pgx.ConnPool,

result:= make(Prices, len(names))

failed:= 0

for i, c:= range names {
p, err:= GetCardLatestHighest(pool, c, source)
if err!=nil {
return nil, err
// Record this as a failure
failed++

// Insert a placeholder
p = Price{
Name: c,
Set: "Unknown",
Price: -1,
Source: source,
}
}

result[i] = p
}

// If we fail to fetch more than 1/3 of prices for this bulk
// set, we error out
if failed >= len(names) / 3 {
return nil, fmt.Errorf("too many fetch failures")
}

return result, nil
}

0 comments on commit 355ab1c

Please sign in to comment.