@@ -8,13 +8,12 @@ import (
88 "context"
99 "encoding/hex"
1010 "errors"
11- "eth2-crawler/graph/model"
12- "eth2-crawler/store/peerstore"
1311 "fmt"
1412 "time"
1513
14+ "eth2-crawler/graph/model"
1615 "eth2-crawler/models"
17-
16+ "eth2-crawler/store/peerstore"
1817 "eth2-crawler/utils/config"
1918
2019 "github.com/libp2p/go-libp2p-core/peer"
@@ -30,18 +29,6 @@ type mongoStore struct {
3029 timeout time.Duration
3130}
3231
33- func (s * mongoStore ) Upsert (ctx context.Context , peer * models.Peer ) error {
34- _ , err := s .View (ctx , peer .ID )
35- if err != nil {
36- if errors .Is (err , peerstore .ErrPeerNotFound ) {
37- return s .Create (ctx , peer )
38- }
39- return err
40- }
41-
42- return s .Update (ctx , peer )
43- }
44-
4532func (s * mongoStore ) Create (ctx context.Context , peer * models.Peer ) error {
4633 _ , err := s .View (ctx , peer .ID )
4734 if err != nil {
@@ -58,7 +45,7 @@ func (s *mongoStore) Update(ctx context.Context, peer *models.Peer) error {
5845 filter := bson.D {
5946 {Key : "_id" , Value : peer .ID },
6047 }
61- _ , err := s .coll .UpdateOne (ctx , filter , bson. D {{ Key : "$set" , Value : peer }} )
48+ _ , err := s .coll .ReplaceOne (ctx , filter , peer )
6249 if err != nil {
6350 return err
6451 }
0 commit comments