Skip to content

Commit

Permalink
chore: replace T with *T
Browse files Browse the repository at this point in the history
  • Loading branch information
polebug committed Nov 27, 2023
1 parent d3cc7f2 commit 45f7f69
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion internal/database/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Client interface {
Session
Transaction

SaveFeeds(ctx context.Context, feeds []schema.Feed) error
SaveFeeds(ctx context.Context, feeds []*schema.Feed) error
}

type Session interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/database/dialer/cockroach/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *client) createPartitionTable(ctx context.Context, name, template string
}

// SaveFeeds saves feeds and indexes to the database.
func (c *client) SaveFeeds(ctx context.Context, feeds []schema.Feed) error {
func (c *client) SaveFeeds(ctx context.Context, feeds []*schema.Feed) error {
if c.partition {
return c.saveFeedsPartitioned(ctx, feeds)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/database/dialer/cockroach/client_partitioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
)

// saveFeedsPartitioned saves feeds in partitioned tables.
func (c *client) saveFeedsPartitioned(ctx context.Context, feeds []schema.Feed) error {
partitions := make(map[string][]schema.Feed)
func (c *client) saveFeedsPartitioned(ctx context.Context, feeds []*schema.Feed) error {
partitions := make(map[string][]*schema.Feed)

// Group feeds by partition name.
for _, feed := range feeds {
var feedTable table.Feed

name := feedTable.PartitionName(lo.ToPtr(feed))
name := feedTable.PartitionName(feed)

if _, exists := partitions[name]; !exists {
partitions[name] = make([]schema.Feed, 0)
partitions[name] = make([]*schema.Feed, 0)
}

partitions[name] = append(partitions[name], feed)
Expand Down Expand Up @@ -67,7 +67,7 @@ func (c *client) saveFeedsPartitioned(ctx context.Context, feeds []schema.Feed)
}

// saveIndexesPartitioned saves indexes in partitioned tables.
func (c *client) saveIndexesPartitioned(ctx context.Context, feeds []schema.Feed) error {
func (c *client) saveIndexesPartitioned(ctx context.Context, feeds []*schema.Feed) error {
indexes := make(table.Indexes, 0)

if err := indexes.Import(feeds); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions internal/database/dialer/cockroach/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ func TestClient(t *testing.T) {
name string
driver database.Driver
partition bool
feedCreated []schema.Feed
feedUpdated []schema.Feed
feedCreated []*schema.Feed
feedUpdated []*schema.Feed
}{
{
name: "cockroach",
driver: database.DriverCockroach,
partition: true,
feedCreated: []schema.Feed{
feedCreated: []*schema.Feed{
{
ID: "0xddc42d4de320638dda200a59938514f7230bf6022355c6a8a7c39b9903598ced",
Chain: lo.ToPtr(filter.ChainEthereumMainnet),
From: "0x566b8087067638b0cb16311e0f05bee58186e787",
To: "0x9e05155e5d924c179b39a8b9b427c1bea06face3",
Type: filter.TypeTransactionTransfer,
Actions: []schema.Action{
Actions: []*schema.Action{
{
Type: filter.TypeTransactionTransfer,
From: "0x000000A52a03835517E9d193B3c27626e1Bc96b1",
Expand All @@ -53,14 +53,14 @@ func TestClient(t *testing.T) {
Timestamp: uint64(time.Now().Unix()),
},
},
feedUpdated: []schema.Feed{
feedUpdated: []*schema.Feed{
{
ID: "0xddc42d4de320638dda200a59938514f7230bf6022355c6a8a7c39b9903598ced",
Chain: lo.ToPtr(filter.ChainEthereumMainnet),
From: "0x566b8087067638b0cb16311e0f05bee58186e787",
To: "0x9e05155e5d924c179b39a8b9b427c1bea06face3",
Type: filter.TypeTransactionTransfer,
Actions: []schema.Action{
Actions: []*schema.Action{
{
Type: filter.TypeTransactionTransfer,
From: "0x566b8087067638b0cb16311e0f05bee58186e787",
Expand All @@ -87,7 +87,7 @@ func TestClient(t *testing.T) {
})

// Dial the database
client, err := dialer.Dial(context.Background(), database.Config{
client, err := dialer.Dial(context.Background(), &database.Config{
Driver: testcase.driver,
URI: dataSourceName,
Partition: testcase.partition,
Expand Down
16 changes: 9 additions & 7 deletions internal/database/dialer/cockroach/table/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *Feed) PartitionName(feed *schema.Feed) string {
f.Timestamp.Year(), int(math.Ceil(float64(f.Timestamp.Month())/3)))
}

func (f *Feed) Import(feed schema.Feed) error {
func (f *Feed) Import(feed *schema.Feed) error {
f.ID = feed.ID
f.Chain = feed.Chain.FullName()
f.Platform = feed.Platform
Expand All @@ -70,7 +70,8 @@ func (f *Feed) Import(feed schema.Feed) error {
}

for _, action := range feed.Actions {
var item FeedAction
item := new(FeedAction)

if err := item.Import(action); err != nil {
return fmt.Errorf("invalid action: %w", err)
}
Expand All @@ -83,11 +84,12 @@ func (f *Feed) Import(feed schema.Feed) error {

var _ schema.FeedsTransformer = (*Feeds)(nil)

type Feeds []Feed
type Feeds []*Feed

func (f *Feeds) Import(feeds []schema.Feed) error {
func (f *Feeds) Import(feeds []*schema.Feed) error {
for _, feed := range feeds {
var item Feed
item := new(Feed)

if err := item.Import(feed); err != nil {
return err
}
Expand Down Expand Up @@ -145,7 +147,7 @@ type FeedAction struct {
Metadata json.RawMessage `json:"metadata"`
}

func (f *FeedAction) Import(action schema.Action) (err error) {
func (f *FeedAction) Import(action *schema.Action) (err error) {
f.Tag = action.Type.Tag().String()
f.Type = action.Type.Name()
f.From = action.From
Expand All @@ -164,7 +166,7 @@ var (
_ driver.Valuer = (*FeedActions)(nil)
)

type FeedActions []FeedAction
type FeedActions []*FeedAction

//goland:noinspection ALL
func (f *FeedActions) Scan(value any) error {
Expand Down
15 changes: 8 additions & 7 deletions internal/database/dialer/cockroach/table/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (i *Index) PartitionName() string {

var _ schema.FeedTransformer = (*Index)(nil)

func (i *Index) Import(feed schema.Feed) error {
func (i *Index) Import(feed *schema.Feed) error {
i.ID = feed.ID
i.Chain = feed.Chain.FullName()
i.Platform = feed.Platform
Expand All @@ -52,10 +52,10 @@ func (i *Index) Import(feed schema.Feed) error {

var _ schema.FeedsTransformer = (*Indexes)(nil)

type Indexes []Index
type Indexes []*Index

func (i *Indexes) Import(feed []schema.Feed) error {
*i = make([]Index, 0, len(feed))
func (i *Indexes) Import(feed []*schema.Feed) error {
*i = make([]*Index, 0, len(feed))

for _, feed := range feed {
var index Index
Expand Down Expand Up @@ -91,10 +91,11 @@ func (i *Indexes) Import(feed []schema.Feed) error {
continue
}

index.Owner = address
index.Direction = direction
data := index
data.Owner = address
data.Direction = direction

*i = append(*i, index)
*i = append(*i, &data)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/database/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/naturalselectionlabs/rss3-node/internal/database/dialer/cockroach"
)

func Dial(ctx context.Context, config database.Config) (database.Client, error) {
func Dial(ctx context.Context, config *database.Config) (database.Client, error) {
switch config.Driver {
case database.DriverCockroach:
return cockroach.Dial(ctx, config.URI, config.Partition)
Expand Down
4 changes: 2 additions & 2 deletions schema/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package schema
import "github.com/naturalselectionlabs/rss3-node/schema/filter"

type FeedTransformer interface {
Import(feed Feed) error
Import(feed *Feed) error
}

type FeedsTransformer interface {
Import(feed []Feed) error
Import(feed []*Feed) error
}

type Feed struct {
Expand Down
2 changes: 1 addition & 1 deletion schema/feed_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package schema
import "github.com/naturalselectionlabs/rss3-node/schema/filter"

type ActionTransformer interface {
Import(action Action) error
Import(action *Action) error
}

type Action struct {
Expand Down

0 comments on commit 45f7f69

Please sign in to comment.