Skip to content

Commit

Permalink
feat: refactor read store (#615)
Browse files Browse the repository at this point in the history
* feat: improve queries performance and refactor storage read part

* fix: post commit effective volumes rendering

* fix: from review
  • Loading branch information
gfyrag authored Dec 20, 2024
1 parent ee5e88c commit b41fda3
Show file tree
Hide file tree
Showing 93 changed files with 4,063 additions and 3,347 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stoewer/go-strcase v1.3.0
github.com/stretchr/testify v1.10.0
github.com/uptrace/bun v1.2.6
github.com/uptrace/bun/dialect/pgdialect v1.2.6
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
12 changes: 12 additions & 0 deletions internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "github.com/formancehq/ledger/internal"
- [func \(a Account\) GetAddress\(\) string](<#Account.GetAddress>)
- [type AccountMetadata](<#AccountMetadata>)
- [type AccountsVolumes](<#AccountsVolumes>)
- [type AggregatedVolumes](<#AggregatedVolumes>)
- [type BalancesByAssets](<#BalancesByAssets>)
- [type BalancesByAssetsByAccounts](<#BalancesByAssetsByAccounts>)
- [type Configuration](<#Configuration>)
Expand Down Expand Up @@ -207,6 +208,17 @@ type AccountsVolumes struct {
}
```

<a name="AggregatedVolumes"></a>
## type AggregatedVolumes



```go
type AggregatedVolumes struct {
Aggregated VolumesByAssets `bun:"aggregated,type:jsonb"`
}
```

<a name="BalancesByAssets"></a>
## type BalancesByAssets

Expand Down
18 changes: 9 additions & 9 deletions internal/api/bulking/mocks_ledger_controller_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions internal/api/common/mocks_ledger_controller_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 8 additions & 14 deletions internal/api/v1/controllers_accounts_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,26 @@ import (

"errors"
"github.com/formancehq/go-libs/v2/api"
"github.com/formancehq/go-libs/v2/bun/bunpaginate"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/ledger/internal/api/common"
ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger"
)

func countAccounts(w http.ResponseWriter, r *http.Request) {
l := common.LedgerFromContext(r.Context())

query, err := bunpaginate.Extract[ledgercontroller.ListAccountsQuery](r, func() (*ledgercontroller.ListAccountsQuery, error) {
options, err := getPaginatedQueryOptionsOfPITFilterWithVolumes(r)
if err != nil {
return nil, err
}
options.QueryBuilder, err = buildAccountsFilterQuery(r)
if err != nil {
return nil, err
}
return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil
})
rq, err := getResourceQuery[any](r)
if err != nil {
api.BadRequest(w, common.ErrValidation, err)
return
}

rq.Builder, err = buildAccountsFilterQuery(r)
if err != nil {
api.BadRequest(w, common.ErrValidation, err)
return
}

count, err := l.CountAccounts(r.Context(), *query)
count, err := l.CountAccounts(r.Context(), *rq)
if err != nil {
switch {
case errors.Is(err, ledgercontroller.ErrInvalidQuery{}) || errors.Is(err, ledgercontroller.ErrMissingFeature{}):
Expand Down
Loading

0 comments on commit b41fda3

Please sign in to comment.