packages/reflex-cache: pass content to ipfs_fetch_task directly if possible
This commit is contained in:
parent
089e570054
commit
4f9e72af6c
2 changed files with 8 additions and 5 deletions
|
@ -13,9 +13,12 @@ class IPFSController:
|
||||||
self.__nix = nixCache
|
self.__nix = nixCache
|
||||||
self.__db = db
|
self.__db = db
|
||||||
|
|
||||||
def ipfs_fetch_task(self, callback, nar, hint=None):
|
def ipfs_fetch_task(self, callback, nar, hint=None, content=None):
|
||||||
|
if content == None:
|
||||||
print(f"Downloading NAR: {nar}")
|
print(f"Downloading NAR: {nar}")
|
||||||
code, _, content = self.__nix.try_all("get", nar, hint)
|
code, _, content = self.__nix.try_all("get", nar, hint)
|
||||||
|
else:
|
||||||
|
code = 200
|
||||||
if code == 200:
|
if code == 200:
|
||||||
if nar.endswith(".nar.xz"):
|
if nar.endswith(".nar.xz"):
|
||||||
print(f"Attempt decompression of {nar}")
|
print(f"Attempt decompression of {nar}")
|
||||||
|
|
|
@ -49,7 +49,7 @@ class ReflexHTTPServiceHandler(BaseHTTPRequestHandler):
|
||||||
resultHash = self._db.get_path(self.path)
|
resultHash = self._db.get_path(self.path)
|
||||||
|
|
||||||
if resultHash == None:
|
if resultHash == None:
|
||||||
code, cache, _ = self._nix.try_all("get", self.path)
|
code, cache, content = self._nix.try_all("get", self.path)
|
||||||
if code != 200:
|
if code != 200:
|
||||||
self.send_response(404)
|
self.send_response(404)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
@ -75,7 +75,7 @@ class ReflexHTTPServiceHandler(BaseHTTPRequestHandler):
|
||||||
# already removed
|
# already removed
|
||||||
pass
|
pass
|
||||||
f = self._executor_nar.submit(
|
f = self._executor_nar.submit(
|
||||||
self._ipfs.ipfs_fetch_task, cb, self.path, cache
|
self._ipfs.ipfs_fetch_task, cb, self.path, cache, content
|
||||||
)
|
)
|
||||||
self._workSet.add((self.path, f))
|
self._workSet.add((self.path, f))
|
||||||
_, code, resultHash = f.result()
|
_, code, resultHash = f.result()
|
||||||
|
|
Loading…
Reference in a new issue