From c19cc5c44d823ff62944decb5cf6ee1fe3dd5f89 Mon Sep 17 00:00:00 2001 From: nabarun Date: Fri, 3 Jun 2022 14:45:52 +0530 Subject: [PATCH] Select required fields in transaction_cids --- pkg/eth/cid_retriever.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/eth/cid_retriever.go b/pkg/eth/cid_retriever.go index 04a5c719..c554be75 100644 --- a/pkg/eth/cid_retriever.go +++ b/pkg/eth/cid_retriever.go @@ -673,7 +673,9 @@ func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockNumber(blockNumber int64) // https://github.com/go-gorm/gorm/issues/4083#issuecomment-778883283 // Will use join for TransactionCids once preload for 1:N is supported. - err := ecr.gormDB.Preload("TransactionCids").Joins("IPLD").Find(&headerCIDs, "block_number = ?", blockNumber).Error + err := ecr.gormDB.Preload("TransactionCids", func(tx *gorm.DB) *gorm.DB { + return tx.Select("cid", "tx_hash", "index", "src", "dst", "header_id") + }).Joins("IPLD").Find(&headerCIDs, "block_number = ?", blockNumber).Error if err != nil { log.Error("header cid retrieval error") return nil, err @@ -690,7 +692,9 @@ func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockHash(blockHash common.Has // https://github.com/go-gorm/gorm/issues/4083#issuecomment-778883283 // Will use join for TransactionCids once preload for 1:N is supported. - err := ecr.gormDB.Preload("TransactionCids").Joins("IPLD").First(&headerCID, "block_hash = ?", blockHash.String()).Error + err := ecr.gormDB.Preload("TransactionCids", func(tx *gorm.DB) *gorm.DB { + return tx.Select("cid", "tx_hash", "index", "src", "dst", "header_id") + }).Joins("IPLD").First(&headerCID, "block_hash = ?", blockHash.String()).Error if err != nil { log.Error("header cid retrieval error") return headerCID, err