1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-03 04:38:38 -04:00

Store currency/security values/prices using big.Rat natively

This adds 'shadow' types used only by the store/db internal package whch
handle converting these types to their DB-equivalent values. This change
should allow reports to be generated significantly faster since it
allows a large portion of the computation to be shifted to the database
engines.
This commit is contained in:
2017-12-12 19:40:38 -05:00
parent 483adb5c56
commit a357d38eee
22 changed files with 695 additions and 201 deletions

View File

@ -147,18 +147,12 @@ func luaAccount__index(L *lua.LState) int {
return 1
}
func balanceFromSplits(splits *[]*models.Split) (*big.Rat, error) {
var balance, tmp big.Rat
func balanceFromSplits(splits *[]*models.Split) *big.Rat {
var balance big.Rat
for _, s := range *splits {
rat_amount, err := models.GetBigAmount(s.Amount)
if err != nil {
return nil, err
}
tmp.Add(&balance, rat_amount)
balance.Set(&tmp)
balance.Add(&balance, &s.Amount.Rat)
}
return &balance, nil
return &balance
}
func luaAccountBalance(L *lua.LState) int {
@ -196,14 +190,12 @@ func luaAccountBalance(L *lua.LState) int {
if err != nil {
panic("Failed to fetch splits for account:" + err.Error())
}
rat, err := balanceFromSplits(splits)
if err != nil {
panic("Failed to calculate balance for account:" + err.Error())
}
rat := balanceFromSplits(splits)
b := &Balance{
Amount: rat,
Amount: models.Amount{*rat},
Security: security,
}
L.Push(BalanceToLua(L, b))
return 1