@@ -11,6 +11,7 @@ import (
11
11
"github.com/benleb/gloomberg/internal/cache"
12
12
"github.com/benleb/gloomberg/internal/gbl"
13
13
"github.com/benleb/gloomberg/internal/gbnode"
14
+ "github.com/benleb/gloomberg/internal/style"
14
15
"github.com/charmbracelet/lipgloss"
15
16
"github.com/ethereum/go-ethereum/common"
16
17
"github.com/spf13/viper"
@@ -82,28 +83,29 @@ func NewCollection(contractAddress common.Address, name string, nodes *gbnode.No
82
83
var collectionName string
83
84
84
85
cache := cache .New (ctx )
85
- nameInCache := false
86
86
87
87
if name != "" {
88
88
collectionName = name
89
- } else if viper .GetBool ("redis.enabled" ) {
90
- // check if the collection is already in the cache
91
- if name , err := cache .GetCollectionName (contractAddress ); err == nil && name != "" {
89
+ } else {
90
+ if name , err := cache .GetCollectionName (contractAddress ); err == nil {
92
91
gbl .Log .Infof ("cache | cached collection name: %s" , name )
93
92
94
- collectionName = name
95
- nameInCache = true
96
- }
97
- } else {
98
- collectionName = nodes .GetRandomNode ().GetCollectionName (contractAddress )
99
- }
93
+ if name != "" {
94
+ collectionName = name
95
+ }
96
+ } else if name , err := nodes .GetRandomNode ().GetCollectionName (contractAddress ); err == nil {
97
+ gbl .Log .Infof ("chain | collection name via contract call: %s" , name )
100
98
101
- if collectionName != "" && ! nameInCache {
102
- // cache collection name
103
- if viper .GetBool ("redis.enabled" ) {
104
- gbl .Log .Infof ("cache | caching collection name: %s" , collectionName )
99
+ if name != "" {
100
+ collectionName = name
101
+ }
105
102
103
+ // cache collection name
106
104
cache .CacheCollectionName (contractAddress , collectionName )
105
+ } else {
106
+ gbl .Log .Errorf ("error getting collection name, using: %s | %s" , style .ShortenAddress (& contractAddress ), err )
107
+
108
+ collectionName = style .ShortenAddress (& contractAddress )
107
109
}
108
110
}
109
111
0 commit comments