refactor: add a local param to StorageService.GetCachedStorageLocations so we don't spam the local provider store on every poll
This commit is contained in:
parent
8c4ebeccd4
commit
73dc22a71e
|
@ -34,7 +34,7 @@ func (m MediatorDefault) SignMessageSimple(message []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MediatorDefault) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error) {
|
func (m MediatorDefault) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error) {
|
||||||
return m.Services().Storage().GetCachedStorageLocations(hash, kinds)
|
return m.Services().Storage().GetCachedStorageLocations(hash, kinds, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MediatorDefault) SortNodesByScore(nodes []*encoding.NodeId) ([]*encoding.NodeId, error) {
|
func (m MediatorDefault) SortNodesByScore(nodes []*encoding.NodeId) ([]*encoding.NodeId, error) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (n *StorageService) ProviderStore() storage.ProviderStore {
|
||||||
return n.providerStore
|
return n.providerStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StorageService) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error) {
|
func (s *StorageService) GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType, local bool) (map[string]storage.StorageLocation, error) {
|
||||||
locations := make(map[string]storage.StorageLocation)
|
locations := make(map[string]storage.StorageLocation)
|
||||||
|
|
||||||
locationMap, err := s.readStorageLocationsFromDB(hash)
|
locationMap, err := s.readStorageLocationsFromDB(hash)
|
||||||
|
@ -81,14 +81,16 @@ func (s *StorageService) GetCachedStorageLocations(hash *encoding.Multihash, kin
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
local := s.getLocalStorageLocation(hash, kinds)
|
if local {
|
||||||
if local != nil {
|
localLocation := s.getLocalStorageLocation(hash, kinds)
|
||||||
nodeIDStr, err := s.Services().P2P().NodeId().ToString()
|
if localLocation != nil {
|
||||||
if err != nil {
|
nodeIDStr, err := s.Services().P2P().NodeId().ToString()
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
locations[nodeIDStr] = local
|
locations[nodeIDStr] = localLocation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(locationMap) == 0 {
|
if len(locationMap) == 0 {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type StorageService interface {
|
type StorageService interface {
|
||||||
SetProviderStore(store storage.ProviderStore)
|
SetProviderStore(store storage.ProviderStore)
|
||||||
ProviderStore() storage.ProviderStore
|
ProviderStore() storage.ProviderStore
|
||||||
GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error)
|
GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType, local bool) (map[string]storage.StorageLocation, error)
|
||||||
AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.NodeId, location storage.StorageLocation, message []byte) error
|
AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.NodeId, location storage.StorageLocation, message []byte) error
|
||||||
DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error)
|
DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error)
|
||||||
DownloadBytesByCID(cid *encoding.CID) ([]byte, error)
|
DownloadBytesByCID(cid *encoding.CID) ([]byte, error)
|
||||||
|
|
|
@ -33,7 +33,7 @@ type StorageLocationProviderImpl struct {
|
||||||
func (s *StorageLocationProviderImpl) Start() error {
|
func (s *StorageLocationProviderImpl) Start() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
s.uris, err = s.services.Storage().GetCachedStorageLocations(s.hash, s.types)
|
s.uris, err = s.services.Storage().GetCachedStorageLocations(s.hash, s.types, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func (s *StorageLocationProviderImpl) Start() error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
newUris, err := s.services.Storage().GetCachedStorageLocations(s.hash, s.types)
|
newUris, err := s.services.Storage().GetCachedStorageLocations(s.hash, s.types, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.mutex.Unlock()
|
s.mutex.Unlock()
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue