store loop on storage

This commit is contained in:
Lex Berezhny 2019-01-07 20:23:18 -05:00
parent 2c84b7a7dd
commit 5ca0ebcbb2

View file

@ -132,10 +132,11 @@ class SQLiteStorage(SQLiteMixin):
); );
""" """
def __init__(self, path): def __init__(self, path, loop=None):
super().__init__(path) super().__init__(path)
self.content_claim_callbacks = {} self.content_claim_callbacks = {}
self.check_should_announce_lc = None self.check_should_announce_lc = None
self.loop = loop or asyncio.get_event_loop()
async def open(self): async def open(self):
await super().open() await super().open()
@ -219,7 +220,7 @@ class SQLiteStorage(SQLiteMixin):
def should_single_announce_blobs(self, blob_hashes, immediate=False): def should_single_announce_blobs(self, blob_hashes, immediate=False):
def set_single_announce(transaction): def set_single_announce(transaction):
now = asyncio.get_event_loop().time() now = self.loop.time()
for blob_hash in blob_hashes: for blob_hash in blob_hashes:
if immediate: if immediate:
transaction.execute( transaction.execute(
@ -234,7 +235,7 @@ class SQLiteStorage(SQLiteMixin):
def get_blobs_to_announce(self): def get_blobs_to_announce(self):
def get_and_update(transaction): def get_and_update(transaction):
timestamp = asyncio.get_event_loop().time() timestamp = self.loop.time()
if conf.settings['announce_head_blobs_only']: if conf.settings['announce_head_blobs_only']:
r = transaction.execute( r = transaction.execute(
"select blob_hash from blob " "select blob_hash from blob "
@ -784,7 +785,7 @@ class SQLiteStorage(SQLiteMixin):
if success: if success:
return self.db.execute( return self.db.execute(
"insert or replace into reflected_stream values (?, ?, ?)", "insert or replace into reflected_stream values (?, ?, ?)",
(sd_hash, reflector_address, asyncio.get_event_loop().time()) (sd_hash, reflector_address, self.loop.time())
) )
return self.db.execute( return self.db.execute(
"delete from reflected_stream where sd_hash=? and reflector_address=?", "delete from reflected_stream where sd_hash=? and reflector_address=?",
@ -796,7 +797,7 @@ class SQLiteStorage(SQLiteMixin):
"select s.sd_hash from stream s " "select s.sd_hash from stream s "
"left outer join reflected_stream r on s.sd_hash=r.sd_hash " "left outer join reflected_stream r on s.sd_hash=r.sd_hash "
"where r.timestamp is null or r.timestamp < ?", "where r.timestamp is null or r.timestamp < ?",
asyncio.get_event_loop().time() - conf.settings['auto_re_reflect_interval'] self.loop.time() - conf.settings['auto_re_reflect_interval']
) )