refactor: simplify add_completed_blob + changelog
This commit is contained in:
parent
adac6b21e3
commit
b91181e640
3 changed files with 6 additions and 18 deletions
|
@ -25,6 +25,7 @@ at anytime.
|
|||
*
|
||||
|
||||
### Changed
|
||||
* refactor `add_completed_blobs` on storage.py, simplifying into less queries
|
||||
* check headers file integrity on startup, removing/truncating the file to force re-download when necessary
|
||||
* support partial headers file download from S3
|
||||
* changed txrequests for treq
|
||||
|
|
|
@ -208,27 +208,15 @@ class SQLiteStorage(object):
|
|||
|
||||
# # # # # # # # # blob functions # # # # # # # # #
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def add_completed_blob(self, blob_hash, length, next_announce_time, should_announce):
|
||||
def add_completed_blob(self, blob_hash, length, next_announce_time, should_announce, status="finished"):
|
||||
log.debug("Adding a completed blob. blob_hash=%s, length=%i", blob_hash, length)
|
||||
yield self.add_known_blob(blob_hash, length)
|
||||
yield self.set_blob_status(blob_hash, "finished")
|
||||
yield self.set_should_announce(blob_hash, next_announce_time, should_announce)
|
||||
yield self.db.runOperation(
|
||||
"update blob set blob_length=? where blob_hash=?", (length, blob_hash)
|
||||
)
|
||||
values = (blob_hash, length, next_announce_time or 0, int(bool(should_announce)), status, 0, 0)
|
||||
return self.db.runOperation("insert or replace into blob values (?, ?, ?, ?, ?, ?, ?)", values)
|
||||
|
||||
def set_should_announce(self, blob_hash, next_announce_time, should_announce):
|
||||
next_announce_time = next_announce_time or 0
|
||||
should_announce = 1 if should_announce else 0
|
||||
return self.db.runOperation(
|
||||
"update blob set next_announce_time=?, should_announce=? where blob_hash=?",
|
||||
(next_announce_time, should_announce, blob_hash)
|
||||
)
|
||||
|
||||
def set_blob_status(self, blob_hash, status):
|
||||
return self.db.runOperation(
|
||||
"update blob set status=? where blob_hash=?", (status, blob_hash)
|
||||
(next_announce_time or 0, int(bool(should_announce)), blob_hash)
|
||||
)
|
||||
|
||||
def get_blob_status(self, blob_hash):
|
||||
|
|
|
@ -98,8 +98,7 @@ class StorageTest(unittest.TestCase):
|
|||
@defer.inlineCallbacks
|
||||
def store_fake_blob(self, blob_hash, blob_length=100, next_announce=0, should_announce=0):
|
||||
yield self.storage.add_completed_blob(blob_hash, blob_length, next_announce,
|
||||
should_announce)
|
||||
yield self.storage.set_blob_status(blob_hash, "finished")
|
||||
should_announce, "finished")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def store_fake_stream_blob(self, stream_hash, blob_hash, blob_num, length=100, iv="DEADBEEF"):
|
||||
|
|
Loading…
Reference in a new issue