forked from LBRYCommunity/lbry-sdk
fix duplicate/buffering problem
fix problem where get request takes time to respond, in this time it can receive more get requests that each manage to start downloading
This commit is contained in:
parent
28f66e30dd
commit
3e7c09bb44
2 changed files with 12 additions and 3 deletions
|
@ -134,6 +134,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.current_db_revision = 1
|
self.current_db_revision = 1
|
||||||
self.run_server = True
|
self.run_server = True
|
||||||
self.session = None
|
self.session = None
|
||||||
|
self.waiting_on = {}
|
||||||
self.known_dht_nodes = KNOWN_DHT_NODES
|
self.known_dht_nodes = KNOWN_DHT_NODES
|
||||||
self.platform_info = {
|
self.platform_info = {
|
||||||
"processor": platform.processor(),
|
"processor": platform.processor(),
|
||||||
|
@ -867,6 +868,10 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
elif not os.path.isdir(download_directory):
|
elif not os.path.isdir(download_directory):
|
||||||
download_directory = self.download_directory
|
download_directory = self.download_directory
|
||||||
|
|
||||||
|
def _remove_from_wait(r):
|
||||||
|
del self.waiting_on[name]
|
||||||
|
return r
|
||||||
|
|
||||||
def _disp_file(f):
|
def _disp_file(f):
|
||||||
file_path = os.path.join(self.download_directory, f.file_name)
|
file_path = os.path.join(self.download_directory, f.file_name)
|
||||||
log.info("[" + str(datetime.now()) + "] Already downloaded: " + str(f.stream_hash) + " --> " + file_path)
|
log.info("[" + str(datetime.now()) + "] Already downloaded: " + str(f.stream_hash) + " --> " + file_path)
|
||||||
|
@ -891,8 +896,10 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
self.waiting_on[name] = True
|
||||||
d = self._check_history(name)
|
d = self._check_history(name)
|
||||||
d.addCallback(lambda lbry_file: _get_stream(name) if not lbry_file else _disp_file(lbry_file))
|
d.addCallback(lambda lbry_file: _get_stream(name) if not lbry_file else _disp_file(lbry_file))
|
||||||
|
d.addCallback(_remove_from_wait)
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -1382,10 +1389,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
if 'name' in p.keys():
|
if 'name' in p.keys():
|
||||||
name = p['name']
|
name = p['name']
|
||||||
|
if p['name'] not in self.waiting_on.keys():
|
||||||
d = self._download_name(name=name, timeout=timeout, download_directory=download_directory)
|
d = self._download_name(name=name, timeout=timeout, download_directory=download_directory)
|
||||||
d.addCallback(lambda message: self._render_response(message, OK_CODE))
|
d.addCallback(lambda message: self._render_response(message, OK_CODE))
|
||||||
else:
|
else:
|
||||||
d = server.failure
|
d = server.failure
|
||||||
|
else:
|
||||||
|
d = server.failure
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,6 @@ class GetStream(object):
|
||||||
self.download_path = os.path.join(downloader.download_directory, downloader.file_name)
|
self.download_path = os.path.join(downloader.download_directory, downloader.file_name)
|
||||||
d.addCallback(lambda _: log.info("Downloading " + str(self.stream_hash) + " --> " + str(self.download_path)))
|
d.addCallback(lambda _: log.info("Downloading " + str(self.stream_hash) + " --> " + str(self.download_path)))
|
||||||
d.addCallback(lambda _: downloader.start())
|
d.addCallback(lambda _: downloader.start())
|
||||||
d.callback()
|
|
||||||
|
|
||||||
class FetcherDaemon(object):
|
class FetcherDaemon(object):
|
||||||
def __init__(self, session, lbry_file_manager, lbry_file_metadata_manager, wallet, sd_identifier, autofetcher_conf,
|
def __init__(self, session, lbry_file_manager, lbry_file_metadata_manager, wallet, sd_identifier, autofetcher_conf,
|
||||||
|
|
Loading…
Reference in a new issue