forked from LBRYCommunity/lbry-sdk
fix age used in datastore to determine if a value is expired
This commit is contained in:
parent
921ee3c4c1
commit
945da5985e
1 changed files with 3 additions and 11 deletions
|
@ -10,7 +10,7 @@ class DictDataStore(UserDict.DictMixin):
|
||||||
|
|
||||||
def __init__(self, getTime=None):
|
def __init__(self, getTime=None):
|
||||||
# Dictionary format:
|
# Dictionary format:
|
||||||
# { <key>: (<value>, <lastPublished>, <originallyPublished> <originalPublisherID>) }
|
# { <key>: (<contact>, <value>, <lastPublished>, <originallyPublished> <originalPublisherID>) }
|
||||||
self._dict = {}
|
self._dict = {}
|
||||||
if not getTime:
|
if not getTime:
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
@ -35,7 +35,7 @@ class DictDataStore(UserDict.DictMixin):
|
||||||
"""
|
"""
|
||||||
Returns only non-expired peers
|
Returns only non-expired peers
|
||||||
"""
|
"""
|
||||||
return filter(lambda peer: self._getTime() - peer[2] < constants.dataExpireTimeout, self._dict[key])
|
return filter(lambda peer: self._getTime() - peer[3] < constants.dataExpireTimeout, self._dict[key])
|
||||||
|
|
||||||
def removeExpiredPeers(self):
|
def removeExpiredPeers(self):
|
||||||
for key in self._dict.keys():
|
for key in self._dict.keys():
|
||||||
|
@ -46,9 +46,7 @@ class DictDataStore(UserDict.DictMixin):
|
||||||
self._dict[key] = unexpired_peers
|
self._dict[key] = unexpired_peers
|
||||||
|
|
||||||
def hasPeersForBlob(self, key):
|
def hasPeersForBlob(self, key):
|
||||||
if key in self._dict and len(self.filter_bad_and_expired_peers(key)):
|
return True if key in self._dict and len(self.filter_bad_and_expired_peers(key)) else False
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def addPeerToBlob(self, contact, key, compact_address, lastPublished, originallyPublished, originalPublisherID):
|
def addPeerToBlob(self, contact, key, compact_address, lastPublished, originallyPublished, originalPublisherID):
|
||||||
if key in self._dict:
|
if key in self._dict:
|
||||||
|
@ -60,12 +58,6 @@ class DictDataStore(UserDict.DictMixin):
|
||||||
def getPeersForBlob(self, key):
|
def getPeersForBlob(self, key):
|
||||||
return [] if key not in self._dict else [val[1] for val in self.filter_bad_and_expired_peers(key)]
|
return [] if key not in self._dict else [val[1] for val in self.filter_bad_and_expired_peers(key)]
|
||||||
|
|
||||||
def removePeer(self, value):
|
|
||||||
for key in self._dict:
|
|
||||||
self._dict[key] = [val for val in self._dict[key] if val[1] != value]
|
|
||||||
if not self._dict[key]:
|
|
||||||
del self._dict[key]
|
|
||||||
|
|
||||||
def getStoringContacts(self):
|
def getStoringContacts(self):
|
||||||
contacts = set()
|
contacts = set()
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
|
|
Loading…
Add table
Reference in a new issue