Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider implementing has many relation on the BlockEvent model to list BlockEventAttributes #28

Open
pharr117 opened this issue Nov 1, 2023 · 0 comments

Comments

@pharr117
Copy link
Collaborator

pharr117 commented Nov 1, 2023

The first implementation of the BlockEventAttribute model has implemented a belongs to relation on the BlockEvent table. We should consider moving to a has_many relation from BlockEvents -> BlockEventAttributes. This may make insert much faster and reduce the amount of preprocessing needed on the BlockEventAttribute table during batch insert here:

cosmos-indexer/db/events.go

Lines 108 to 136 in 45f92b6

var allAttributes []models.BlockEventAttribute
for index := range blockDBWrapper.BeginBlockEvents {
currAttributes := blockDBWrapper.BeginBlockEvents[index].Attributes
for attrIndex := range currAttributes {
currAttributes[attrIndex].BlockEventID = blockDBWrapper.BeginBlockEvents[index].BlockEvent.ID
currAttributes[attrIndex].BlockEvent = blockDBWrapper.BeginBlockEvents[index].BlockEvent
currAttributes[attrIndex].BlockEventAttributeKey = blockDBWrapper.UniqueBlockEventAttributeKeys[currAttributes[attrIndex].BlockEventAttributeKey.Key]
}
allAttributes = append(allAttributes, currAttributes...)
}
for index := range blockDBWrapper.EndBlockEvents {
currAttributes := blockDBWrapper.EndBlockEvents[index].Attributes
for attrIndex := range currAttributes {
currAttributes[attrIndex].BlockEventID = blockDBWrapper.EndBlockEvents[index].BlockEvent.ID
currAttributes[attrIndex].BlockEvent = blockDBWrapper.EndBlockEvents[index].BlockEvent
currAttributes[attrIndex].BlockEventAttributeKey = blockDBWrapper.UniqueBlockEventAttributeKeys[currAttributes[attrIndex].BlockEventAttributeKey.Key]
}
allAttributes = append(allAttributes, currAttributes...)
}
if len(allAttributes) != 0 {
if err := dbTransaction.Clauses(clause.OnConflict{DoNothing: true}).Create(&allAttributes).Error; err != nil {
config.Log.Error("Error creating begin block event attributes.", err)
return nil
}
}
}

Its possible this could become a one-liner by passing in the attributes as an array. We would probably still need to pre-process the AttributeKeys and apply them to the items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

1 participant