diff --git a/common/priceDB/bulk.go b/common/priceDB/bulk.go index cd61f81..39ad65c 100755 --- a/common/priceDB/bulk.go +++ b/common/priceDB/bulk.go @@ -2,6 +2,8 @@ package priceDB import ( "github.com/jackc/pgx" + + "fmt" ) func GetBulkLatestLowest(pool *pgx.ConnPool, @@ -9,15 +11,32 @@ func GetBulkLatestLowest(pool *pgx.ConnPool, 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 } @@ -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 } \ No newline at end of file