Skip to content

Commit

Permalink
feat: use cache
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Aug 16, 2023
1 parent 34f16e8 commit a29d448
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/core/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ type Account struct {
Metadata Metadata `json:"metadata" swaggertype:"object"`
}

func (v Account) Copy() *Account {
data, err := json.Marshal(v)
if err != nil {
panic(err)
}
ret := &Account{}
if err := json.Unmarshal(data, ret); err != nil {
panic(err)
}
return ret
}

type AccountWithVolumes struct {
Account
Volumes AssetsVolumes `json:"volumes"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/sqlstorage/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func (s *Store) GetAccounts(ctx context.Context, q ledger.AccountsQuery) (api.Cu
}

func (s *Store) GetAccount(ctx context.Context, addr string) (*core.Account, error) {

entry, ok := s.cache.Get(addr)
if ok {
return entry.(*core.AccountWithVolumes).Account.Copy(), nil
}

sb := sqlbuilder.NewSelectBuilder()
sb.Select("address", "metadata").
From(s.schema.Table("accounts")).
Expand Down

0 comments on commit a29d448

Please sign in to comment.